在virtualenv中运行pip时的AttributeError

时间:2015-04-01 07:59:13

标签: python pip virtualenv

我最近使用自制软件将python从2.7.6升级到2.7.9。然后,我尝试了' revirtualise' 现有虚拟环境

sudo virtualenv -p python2.7 existingvenv

但是我收到了这个错误:

Traceback (most recent call last):
  File "venv.../bin/pip", line 7, in <module>
    from pip import main
  File "venv.../lib/python2.7/site-packages/pip/__init__.py", line 9, in <module>
    from pip.log import logger
  File "venv.../lib/python2.7/site-packages/pip/log.py", line 8, in <module>
    from pip import backwardcompat
  File "venv.../lib/python2.7/site-packages/pip/backwardcompat/__init__.py", line 66, in <module>
    from urllib2 import URLError, HTTPError
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 93, in <module>
    import hashlib
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 138, in <module>
    _hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 2352, in <module>
    main()
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 825, in main
    symlink=options.symlink)
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 993, in create_environment
    install_wheel(to_install, py_executable, search_dirs)
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 961, in install_wheel
    'PIP_NO_INDEX': '1'
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 903, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/robertelliott...hflow-app/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1

在上述活动虚拟环境中运行任何pip install x时,我也会收到上述错误。

创建新virtualenv 时,我没有收到错误:

$ virtualenv -p python2.7 newvenv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
New python executable in newenv/bin/python
Installing setuptools, pip...done.

现有的virtualenv中是否有旧的符号链接或其他内容导致问题,我该如何解决?

2 个答案:

答案 0 :(得分:0)

这是因为Python中的一个新功能,它与0.24轮不兼容。您将在Python 2.7系统安装下找到一个名为virtualenv_support的文件夹,其中包含setuptools,pip和wheel的基本安装文件。有一些解决方案。最简单的方法是从virtualenv_support文件夹中删除wheel-0.24 *。如果你想更进一步,你可以下载0.24轮的.whl文件并替换它。

答案 1 :(得分:0)

你试过了吗?

sudo virtualenv --clear -p python2.7 existingvenv