当我在 virtualenv 中时无法 pip 安装包

Unable to pip install packages when I am in a virtualenv

我希望 SO 能够帮助解决这个问题。

当我在 virtualenv 中时,我无法 pip 安装任何包。我在 Windows 7 和 python 2.7.12。

例如,当我这样使用 git bash 时:

(venv2)
me@myhost ~/git/myrepo (master)
$ pip install requests

我收到以下错误:

Collecting requests
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02A438F0>: Failed to establish a new connection: [Errno 11003] getaddrinfo failed',)': /simple/requests/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02A43790>: Failed to establish a new connection: [Errno 11003] getaddrinfo failed',)': /simple/requests/
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02A43B50>: Failed to establish a new connection: [Errno 11003] getaddrinfo failed',)': /simple/requests/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02A43DD0>: Failed to establish a new connection: [Errno 11003] getaddrinfo failed',)': /simple/requests/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02A43E50>: Failed to establish a new connection: [Errno 11003] getaddrinfo failed',)': /simple/requests/
Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

然而,当我不在 virtualenv 中时,我可以 pip install packages 就好了。我已经阅读了很多关于类似错误的 SO 问题,但是 none 非常符合我的情况。

我尝试过的一些事情:卸载并重新安装 python;升级点子;切换 python 个版本。

如果你能给我指出正确的方向,我将不胜感激

老问题,但我刚遇到一个非常相似的问题,但没有发布答案。

当我的存储库在我的 G: 驱动器上时,python 安装在 C: 上。将 repo 移动到 C: 驱动器解决了我的问题,我能够使用 pip 安装我的 venv requirements.txt。

在 G:\

(env) G:\repo\>pip install -r requirements.txt
Collecting flask>=0.11 (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connec
tion broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.conne
ction.VerifiedHTTPSConnection object at 0x0000000004393E10>: Failed to establish
 a new connection: [Errno 11003] getaddrinfo failed',)': /simple/flask/
  Retrying (Retry(total=3, ...

  Could not find a version that satisfies the requirement flask>=0.11 (from -r r
equirements.txt (line 1)) (from versions: )
No matching distribution found for flask>=0.11 (from -r requirements.txt (line 1
))

在 C:\

(env) C:\repo\>pip install -r requirements.txt
Collecting flask>=0.11 (from -r requirements.txt (line 1))
  Using cached Flask-0.12-py2.py3-none-any.whl
...