如何让 pip 在代理服务器后面工作 [英] How to get pip to work behind a proxy server
问题描述
我正在尝试使用 python 包管理器 pip 来安装一个包,它是来自 Internet 的依赖项.但是,我在我大学的代理后面,并且已经设置了 http_proxy
环境变量.但是当我尝试安装这样的包时:
I am trying to use python package manager pip to install a package and it's dependencies from the internet. However I am behind a proxy in my college and have already set the http_proxy
environment variable. But when I try to install a package like this:
pip install TwitterApi
我在日志文件中收到此错误:
I get this error in the log file:
Getting page http://pypi.python.org/simple/TwitterApi
Could not fetch URL http://pypi.python.org/simple/TwitterApi: <urlopen error [Errno 111] Connection refused>
Will skip URL http://pypi.python.org/simple/TwitterApi when looking for download links for TwitterApi
Getting page http://pypi.python.org/simple/
Could not fetch URL http://pypi.python.org/simple/: <urlopen error [Errno 111] Connection refused>
我什至尝试像这样显式设置我的代理变量:
I even tried setting my proxy variable explicitly like this:
pip install --proxy http://user:password@proxyserver:port TwitterApi
但我仍然遇到同样的错误.如何让 pip 在代理服务器后面工作.
But I still get the same error. How do I get pip to work behind a proxy server.
推荐答案
pip的proxy参数,根据pip --help
,格式为scheme://[user:passwd@]proxy.server:port
The pip's proxy parameter is, according to pip --help
, in the form scheme://[user:passwd@]proxy.server:port
您应该使用以下内容:
pip install --proxy http://user:password@proxyserver:port TwitterApi
此外,应该遵守 HTTP_PROXY
环境变量.
Also, the HTTP_PROXY
env var should be respected.
请注意,在早期版本中(无法追踪代码中的更改,抱歉,但文档已更新此处),您必须将 scheme://
部分保留下来才能使其工作,即 pip install --proxy user:password@代理服务器:端口
Note that in earlier versions (couldn't track down the change in the code, sorry, but the doc was updated here), you had to leave the scheme://
part out for it to work, i.e. pip install --proxy user:password@proxyserver:port
这篇关于如何让 pip 在代理服务器后面工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!