Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Avoid importing pkg_resources to speed up import #19098

Copy link
Copy link
Closed
@anntzer

Description

@anntzer
Issue body actions

Describe the bug

Since #17670, sklearn unconditionally imports pkg_resources. Such an import can be very slow (pypa/setuptools#926), so it should be avoided if possible.

Given that the point of #17670 was to improve support for prereleases, a possible fix could be for example to delay importing pkg_resources until needed, e.g.

def parse_version(v):
    if {*v} <= {*"1234567890."}:
        return LooseVersion(v)
    else:
        import pkg_resources
        return pkg_resources.parse_version(v)

Steps/Code to Reproduce

Expected Results

Actual Results

N/A

Versions

System:
    python: 3.9.1 (default, Dec 13 2020, 11:55:53)  [GCC 10.2.0]
executable: /usr/bin/python
   machine: Linux-5.9.14-arch1-1-x86_64-with-glibc2.32

Python dependencies:
          pip: 20.3.3
   setuptools: 51.1.1
      sklearn: 0.23.2
        numpy: 1.19.4
        scipy: 1.5.4
       Cython: 0.29.21
       pandas: 1.1.5
   matplotlib: 3.3.2.post2048+g263120690
       joblib: 1.0.0
threadpoolctl: 2.1.0

Built with OpenMP: True

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.