手动安装pip到virutalenv

时间:2016-01-13 05:07:48

标签: python pip virtualenv

我正在尝试创建一个virtualenv,我将在OSX El Capitan上运行旧版本的Django(1.4.2)和特定版本的Python(2.7.8)。以下是我经历的步骤:

我使用此工作流下载并编译了Python 2.7.8: Is it possible to install another version of Python to Virtualenv?

当我尝试使用指向我新编译的Python2.7.8的--python标志创建一个新的virtualenv时,我收到一条如下所示的错误消息:

  Complete output from command /Users/luka/xxx/virtu...y2_7_8/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/__init__.py", line 15, in <module>
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/vcs/subversion.py", line 9, in <module>
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/index.py", line 30, in <module>
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/wheel.py", line 35, in <module>
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 14, in <module>
  File "/Library/Python/2.7/site-packages/virtualenv-13.1.2-py2.7.egg/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler

如果我用--no-setuptools标志重新运行相同的命令,一切正常,我可以访问我需要的Python版本,但我没有在site-package目录中的pip和setuptools,这是一个问题,因为现在我无法在virtualenv中安装特定版本的Django。我可以简单地将现有的系统级pip安装复制到我的virtualenv中,或者以其他方式安装pip吗?

谢谢! 卢卡

1 个答案:

答案 0 :(得分:1)

您可以在新的virtualenv using the get-pip.py script中安装pip

  1. 下载get-pip.py,例如使用wget或curl
  2. 使用virtualenv的python运行它,即激活virtualenv,然后运行python get-pip.py