pip fails with AttributeError: 'module' ob

2019-02-01 22:10发布

I'm on Fedora. I recently upgraded my system from F20 to F21. Pip was working fine on F20 but after the upgrade to F21 something must have gone wrong. Pip stopped working, every time I enter the command pip <anything> the error below occurs:

Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
    from pip import main
  File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 12, in <module>
    from pip.commands import commands, get_summaries, get_similar_commands
  File "/usr/lib/python2.7/site-packages/pip/commands/__init__.py", line 6, in <module>
    from pip.commands.bundle import BundleCommand
  File "/usr/lib/python2.7/site-packages/pip/commands/bundle.py", line 6, in <module>
    from pip.commands.install import InstallCommand
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 5, in <module>
    from pip.req import InstallRequirement, RequirementSet, parse_requirements
  File "/usr/lib/python2.7/site-packages/pip/req/__init__.py", line 3, in <module>
    from .req_install import InstallRequirement
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 31, in <module>
    from pip.utils import (
  File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 59, in <module>
    def rmtree(dir, ignore_errors=False):
  File "/usr/lib/python2.7/site-packages/pip/_vendor/retrying.py", line 47, in wrap
    @six.wraps(f)
AttributeError: 'module' object has no attribute 'wraps'

7条回答
男人必须洒脱
2楼-- · 2019-02-01 22:42

If you recreate a virtual env that contains a different pip-version you can run into such a scenario:

# virtualenv /tmp/env
New python executable in /tmp/env/bin/python
Installing setuptools, pip...done.

# /tmp/env/bin/pip install --upgrade pip
(...)
Found existing installation: pip 1.5.6
  Uninstalling pip:
    Successfully uninstalled pip
Successfully installed pip

# virtualenv /tmp/env
New python executable in /tmp/env/bin/python
Installing setuptools, pip...done.

# /tmp/env/bin/pip install --upgrade pip
(...)
AttributeError: 'module' object has no attribute 'wraps'

The environment now contains the pip fragments from the previous installation. To fix that you can use the --clean option:

# virtualenv --clear /tmp/env
Deleting tree /tmp/env/lib/python2.7
Not deleting /tmp/env/bin
New python executable in /tmp/env/bin/python
Installing setuptools, pip...done.

Then virtualenv will wipe out the path before it installs the new environment.

If you wanna have an update behavior you can skip virtualenv if (e.g.) bin/python) is present.

# [ ! -x /tmp/env/bin/python ] && virtualenv /tmp/env
查看更多
登录 后发表回答