如何让pip在代理的后面工作

2024-04-26 18:45:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python包管理器pip安装一个包及其依赖项。然而,我在我的大学里支持一个代理,并且已经设置了http_proxy环境变量。但当我尝试安装这样的软件包时:

pip install TwitterApi

我在日志文件中收到此错误:

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>

我甚至尝试如下显式设置代理变量:

pip install --proxy http://user:password@proxyserver:port TwitterApi

但我还是犯了同样的错误。如何让pip在代理服务器后面工作。


Tags: installpiporgpypihttpurl代理错误
3条回答

至少对于pip 1.3.1,它支持http_proxy和https_proxy环境变量。确保两者都定义,因为它将使用https访问PYPI索引。

export https_proxy="http://<proxy.server>:<port>"
pip install TwitterApi

根据pip --help,pip的代理参数的形式是scheme://[user:passwd@]proxy.server:port

您应该使用以下选项:

pip install --proxy http://user:password@proxyserver:port TwitterApi

另外,应该尊重HTTP_PROXYenv变量。

请注意,在早期版本中(抱歉,无法跟踪代码中的更改,但文档已更新here),必须保留scheme://部分才能工作,即pip install --proxy user:password@proxyserver:port

我知道是旧线程,但为了将来参考,--proxy选项现在传递一个“=”

示例:

$ sudo pip install --proxy=http://yourproxy:yourport package_name

相关问题 更多 >