Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylint is unable to import distutils.version under virtualenv #73

Closed
pylint-bot opened this issue Sep 11, 2013 · 23 comments · Fixed by pylint-dev/astroid#672
Closed

pylint is unable to import distutils.version under virtualenv #73

pylint-bot opened this issue Sep 11, 2013 · 23 comments · Fixed by pylint-dev/astroid#672
Labels

Comments

@pylint-bot
Copy link

Originally reported by: Chris Rebert (BitBucket: cvrebert, GitHub: @cvrebert?)


Testcase:

#!python

#!/usr/bin/env python2.7
import distutils.version

Output:

#!txt

************* Module foo
foo.py:1: [C0111(missing-docstring), ] Missing module docstring
foo.py:2: [F0401(import-error), ] Unable to import 'distutils.version'
foo.py:2: [E0611(no-name-in-module), ] No name 'version' in module 'distutils'
foo.py:2: [W0611(unused-import), ] Unused import distutils

Which doesn't agree with Python itself:

#!python

$ python
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils.version
>>> # no error

@pylint-bot
Copy link
Author

Original comment by BitBucket: notsqrt, GitHub: @NotSqrt?:


Came across this issue with the following config:

#!text
No config file found, using default configuration
pylint 1.0.0, 
astroid 1.0.0, common 0.60.0
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
[GCC 4.6.3]

@pylint-bot
Copy link
Author

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


PYTHONPATH pb ?

#!python
[syt@host pylint]$ cat x.py 
import distutils.version
print distutils.version
[syt@host pylint]$ pylint -rn x.py 
************* Module pylint.x
C:  1, 0: Missing module docstring (missing-docstring)
[syt@host pylint]$ pylint --version
pylint 1.0.0, 
astroid 1.0.0, common 0.60.0
Python 2.7.4 (default, Apr 19 2013, 18:28:01) 
[GCC 4.7.3]


@pylint-bot
Copy link
Author

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


can't reproduce

@pylint-bot
Copy link
Author

Original comment by BitBucket: notsqrt, GitHub: @NotSqrt?:


Seems to be messed up by virtualenvs.

Steps to reproduce :

  1. create virtualenv and activate it (with virtualenvwrapper, in 1 command : mktmpenv)
  2. pip install pylint
  3. pylint x.py

(with the same x.py as above)

Fails with version:

pylint 1.0.0, 
astroid 1.0.1, common 0.60.0
Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
[GCC 4.8.1]

@pylint-bot
Copy link
Author

Original comment by Jan Vermaete (BitBucket: jan.vermaete):


I confirm it's related to virtualenv (python -m venv env).
-> it's not 'invalid', IMHO

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (In
tel)] on win32

Astroid: Changeset: 1073 (4b0a497acee0) Merged in AndroWiiid/astroid/dev (pull request #12) …
common: Changeset:1589 (e9fc9f452231) merge default heads
pylint: Changeset:1149 (656d711815bc) fix tests broken due to Windows line ending or by output format change introduced in ed904ee30bc5

@pylint-bot
Copy link
Author

Original comment by BitBucket: fbretel, GitHub: @fbretel?:


Confirmed on Ubuntu 13.10, Python 2.7.5+, pylint 0.26.0 or 1.0.0, astng 0.24.3, common 0.60.0, virtualenv 1.10.1.
May be related to http://stackoverflow.com/a/14293787/421846

@pylint-bot
Copy link
Author

Original comment by BitBucket: elmirjagudin, GitHub: @elmirjagudin?:


This is caused by the monkey-patched distutils package which virtualenv creates.

The virtualenv script only creates distutils/init.py inside it's sandbox, it does not create the distutils/versions.py file. When you do 'import distutils.version', the distutils module will be loaded from the sandbox, but the version module will be loaded from the global location. For example, this is run from inside of "~boris/tst" sandbox:

#!python

$ python
>>> import distutils.version
>>> distutils.__file__
'/home/boris/tst/lib/python2.7/distutils/__init__.pyc'
>>> distutils.version.__file__
'/usr/lib/python2.7/distutils/version.pyc'

However, due to how modules look-up is implemented in logilab.common.modutils, pylint can't locate distutils.version. Pylint will only look for version module in the same directory where it have found it's parent module distutils.

IMHO, the problem lies in logilab.common.modutils._module_file() function. It calls find_module() to locate the module. For any child modules it specifies only parent's directory as the search path.

@pylint-bot
Copy link
Author

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


Removing version: 1.0 (automated comment)

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


@elmirjagudin What is your proposed change? From what I can see, the distutils.__init__ does a fair bit of work to make the namespace work as it does, and the only way pylint could know what's done there is to execute it, which would break the contract of "pylint is a static analysis tool".

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


Is there any conceivable way this will be fixed?

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Probably, it just needs someone to write the patch. We'll look into it after finishing with pylint 1.5.0, that's the main priority for now.

atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 29, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 29, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 29, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable coverage + multiprocessing - generates lots of JSON errors
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 29, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable coverage + multiprocessing - generates lots of JSON errors
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 29, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 29, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 30, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 30, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jun 30, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jul 1, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
atodorov added a commit to atodorov/pykickstart that referenced this issue Jul 1, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
clumens pushed a commit to pykickstart/pykickstart that referenced this issue Jul 5, 2016
- use /usr/bin/env instead of hard-coded /usr/bin/python3
- move mypy checks into the `check` target
- disable pylint import checks for setup.py because of
  pylint-dev/pylint#73 (comment)
jwilk added a commit to jwilk/pydiatra that referenced this issue Jul 24, 2016
Pylint doesn't grok monkey-patched distutils used in virtualenv:
pylint-dev/pylint#73
jwilk added a commit to jwilk/pydiatra that referenced this issue Jul 24, 2016
Pylint doesn't grok monkey-patched distutils used in virtualenv:
pylint-dev/pylint#73
tbielawa added a commit to tbielawa/openshift-ansible that referenced this issue Aug 26, 2016
* Fixes PyLint to run in the virtualenv used for all tests

* Replaced 'LooseVersion' with 'parse_version' from setuptools
- This is a work around for the issue in
  pylint-dev/pylint#73 in which pylint can not
  import disutils.version correctly in a virtualenv.

* Removed the unused function 'delete_hosts' which was causing a
  pylint error as well

* Removed a deprecated pylint pragma option, 'bad-builtin'

* Fixed some import ordering issues it was picky about

* Added another disable for a case where the PyLint suggestion would
  have us altering the container we would be iterating over

* Add code-coverage reports to the unittests with the MINIMUM coverage
  percentage for success set to 70%
- Current test coverage is at 76%
tbielawa added a commit to tbielawa/openshift-ansible that referenced this issue Aug 26, 2016
* Fixes PyLint to run in the virtualenv used for all tests

* Replaced 'LooseVersion' with 'parse_version' from setuptools
- This is a work around for the issue in
  pylint-dev/pylint#73 in which pylint can not
  import disutils.version correctly in a virtualenv.

* Removed the unused function 'delete_hosts' which was causing a
  pylint error as well

* Removed a deprecated pylint pragma option, 'bad-builtin'

* Fixed some import ordering issues it was picky about

* Added another disable for a case where the PyLint suggestion would
  have us altering the container we would be iterating over

* Add code-coverage reports to the unittests with the MINIMUM coverage
  percentage for success set to 70%
- Current test coverage is at 76%
sphuber pushed a commit to aiidateam/aiida-core that referenced this issue Mar 12, 2019
The export version number in newer `aiida-core` versions is no longer a
string but a float. Converting both to `StrictVersion` should solve the
problem. The import of `StrictVersion` from `distutils` triggered an
error in `pylint` and therefore `distutils` is currently ignored until
the issue is addressed: pylint-dev/pylint#73
@feuGeneA
Copy link

feuGeneA commented Apr 5, 2019

Despite the comment from @mattsb42-aws , I'm encountering this problem with Python 3.7.2.

ricardobranco777 added a commit to ricardobranco777/clean_registry that referenced this issue Apr 25, 2019
mzagozen added a commit to mzagozen/nsxramlclient that referenced this issue May 6, 2019
mzagozen added a commit to mzagozen/nsxramlclient that referenced this issue May 6, 2019
mzagozen added a commit to mzagozen/nsxramlclient that referenced this issue May 6, 2019
AWhetter added a commit to pylint-dev/astroid that referenced this issue May 18, 2019
AWhetter added a commit to pylint-dev/astroid that referenced this issue May 20, 2019
PCManticore pushed a commit to pylint-dev/astroid that referenced this issue May 23, 2019
@mcallaghan-bsm
Copy link

When's the next pylint release? We are waiting for this fix :)
https://github.com/PyCQA/pylint/releases

lukpueh added a commit to lukpueh/securesystemslib that referenced this issue Aug 8, 2019
Pylint complains about distutils import in virtualenv (tox):
pylint-dev/pylint#73
```
E: 22, 0: No name 'version' in module 'distutils' (no-name-in-module)
E: 22, 0: Unable to import 'distutils.version.StrictVersion' (import-error)
```

Add inline pylint disable for `no-name-in-module` and
`import-error` checks as workaround for this issue.
lukpueh added a commit to lukpueh/securesystemslib that referenced this issue Aug 14, 2019
Pylint complains about distutils import in virtualenv (tox):
pylint-dev/pylint#73
```
E: 22, 0: No name 'version' in module 'distutils' (no-name-in-module)
E: 22, 0: Unable to import 'distutils.version.StrictVersion' (import-error)
```

Add inline pylint disable for `no-name-in-module` and
`import-error` checks as workaround for this issue.
lukpueh added a commit to lukpueh/securesystemslib that referenced this issue Sep 4, 2019
Pylint complains about distutils import in virtualenv (tox):
pylint-dev/pylint#73
```
E: 22, 0: No name 'version' in module 'distutils' (no-name-in-module)
E: 22, 0: Unable to import 'distutils.version.StrictVersion' (import-error)
```

Add inline pylint disable for `no-name-in-module` and
`import-error` checks as workaround for this issue.
lukpueh added a commit to lukpueh/securesystemslib that referenced this issue Sep 4, 2019
Pylint complains about distutils import in virtualenv (tox):
pylint-dev/pylint#73
```
E: 22, 0: No name 'version' in module 'distutils' (no-name-in-module)
E: 22, 0: Unable to import 'distutils.version.StrictVersion' (import-error)
```

Add inline pylint disable for `no-name-in-module` and
`import-error` checks as workaround for this issue.
melor pushed a commit to melor/pghoard that referenced this issue Oct 26, 2019
Older pylint version had issues with distutils imports:

pylint-dev/pylint#73
melor pushed a commit to melor/pghoard that referenced this issue Oct 26, 2019
Older pylint version had issues with distutils imports:

pylint-dev/pylint#73
tanishqjasoria pushed a commit to tanishqjasoria/securesystemslib that referenced this issue Jan 30, 2020
Pylint complains about distutils import in virtualenv (tox):
pylint-dev/pylint#73
```
E: 22, 0: No name 'version' in module 'distutils' (no-name-in-module)
E: 22, 0: Unable to import 'distutils.version.StrictVersion' (import-error)
```

Add inline pylint disable for `no-name-in-module` and
`import-error` checks as workaround for this issue.
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Following change in the way distutil is stored in setuptools

See pylint-dev/astroid#1321
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Following change in the way distutil is stored in setuptools

See pylint-dev/astroid#1321
Pierre-Sassoulas added a commit that referenced this issue Jan 1, 2022
Following change in the way distutil is stored in setuptools

See pylint-dev/astroid#1321
areveny pushed a commit to areveny/pylint that referenced this issue Jan 3, 2022
Following change in the way distutil is stored in setuptools

See pylint-dev/astroid#1321
rdunklau pushed a commit to Aiven-Open/rohmu that referenced this issue Apr 27, 2022
Older pylint version had issues with distutils imports:

pylint-dev/pylint#73
rdunklau pushed a commit to Aiven-Open/rohmu that referenced this issue Apr 27, 2022
Older pylint version had issues with distutils imports:

pylint-dev/pylint#73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.