Python pip 因 AttributeError 失败:'module' 对象没有属性 'wraps'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29038889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pip fails with AttributeError: 'module' object has no attribute 'wraps'
提问by Theja
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:
我在 Fedora 上。我最近将我的系统从 F20 升级到 F21。Pip 在 F20 上运行良好,但在升级到 F21 之后一定出了问题。Pip停止工作,每次输入命令时都会pip <anything>出现以下错误:
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'
回答by Theja
Okay after trying out all the solutions I could google with no result in sight. I tried to risk and play a little bit. This might not be the safest solution but it worked fine for me.
Seeing that python get-pip.pyresulted in:
好吧,在尝试了所有解决方案后,我可以用谷歌搜索,但看不到任何结果。我试着冒险玩一点。这可能不是最安全的解决方案,但对我来说效果很好。看到python get-pip.py结果是:
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
even when I had pip uninstalled.
I went over to /usr/lib/python2.7/site-packages/to find out two pip directories: pipand pip-6.0.8.dist-info. Removed both immediately. Then tried python get-pip.pyagain. Voila! it worked.
即使我卸载了 pip。我去/usr/lib/python2.7/site-packages/找出两个 pip 目录:pip和pip-6.0.8.dist-info. 立即删除了两个。然后又试了python get-pip.py一次。瞧!有效。
回答by Melissa
This worked:
这有效:
mv /usr/lib/python2.7/site-packages/pip* ./
yum reinstall python-pip
回答by Atli Guemundsson
This occurred in my situation after I had moved the virtualenv directory (along with the project) to a new location, which I clearly shouldn't have done as (reading the doc now) the manual clearly states some [full] hardcoded paths are included in the environment.
这发生在我将 virtualenv 目录(连同项目)移动到一个新位置后的情况,我显然不应该这样做(现在阅读文档)手册清楚地说明了一些[完整]硬编码路径包括在内在环境中。
Deleting the bin/, include/, lib/ and lib64/ directories and then recreating the virtualenv solved the issue for me.
删除 bin/、include/、lib/ 和 lib64/ 目录,然后重新创建 virtualenv 为我解决了这个问题。
I did look into searching for and fixing the full paths in the environment, but fixing it everywhere (besides in the bin/activate* files) didn't seem trivial.
我确实研究过在环境中搜索和修复完整路径,但在任何地方(除了 bin/activate* 文件)修复它似乎并不简单。
回答by Fruch
happend to me on windows with activestate python fresh install I've just used easy_install to downgrade the pip
我在 Windows 上遇到了 activestate python 全新安装我刚刚使用 easy_install 降级了 pip
easy_install pip==7.1.2
and then it was working....
然后它正在工作......
回答by Proddi
If you recreatea virtual env that contains a different pip-version you can run into such a scenario:
如果您重新创建一个包含不同 pip-version的虚拟环境,您可能会遇到这样的情况:
# 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 --cleanoption:
该环境现在包含来自先前安装的 pip 片段。要解决此问题,您可以使用--clean选项:
# 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.
然后 virtualenv 将在安装新环境之前清除路径。
If you wanna have an update behavior you can skip virtualenv if (e.g.) bin/python) is present.
如果你想有一个更新行为,你可以跳过 virtualenv 如果(例如)bin/python)存在。
# [ ! -x /tmp/env/bin/python ] && virtualenv /tmp/env
回答by Yuriy R
I'm on Mac OS, but was able to fix this error by doing mkvirtualenv --system-site-packages XXXXas opposed to mkvirtualenv XXXX.
我在 Mac OS 上,但能够通过执行mkvirtualenv --system-site-packages XXXX而不是mkvirtualenv XXXX.
Running pip install -r requirements.txtin the virtual environment was giving me AttributeError: 'module' object has no attribute 'wraps'before and doesn't anymore.
pip install -r requirements.txt在虚拟环境中运行AttributeError: 'module' object has no attribute 'wraps'之前给了我,现在不再给我了。
回答by Devin Clark
Use easy_install to install a prior version of pip
使用 easy_install 安装先前版本的 pip
easy_install pip==7.0.2
Then use pip to install the version you came down from, in my case it was 9.0.1
然后使用 pip 安装您下载的版本,在我的情况下是 9.0.1
pip install pip==9.0.1

