如何让 pip 在代理服务器后面工作

我试图使用 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 在代理服务器后面工作。

393843 次浏览

The pip's proxy parameter is, according to pip --help, in the form scheme://[user:passwd@]proxy.server:port

You should use the following:

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

Also, the HTTP_PROXY env var should be respected.

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

At least for pip 1.3.1, it honors the http_proxy and https_proxy environment variables. Make sure you define both, as it will access the PYPI index using https.

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

Old thread, I know, but for future reference, the --proxy option is now passed with an "="

Example:

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

at least pip3 also works without "=", however, instead of "http" you might need "https"

Final command, which worked for me:

sudo pip3 install --proxy https://{proxy}:{port} {BINARY}

First Try to set proxy using the following command

SET HTTPS_PROXY=http://proxy.***.com:PORT#

Then Try using the command

pip install ModuleName

On Ubuntu, you can set proxy by using

export http_proxy=http://username:password@proxy:port
export https_proxy=http://username:password@proxy:port

or if you are having SOCKS error use

export all_proxy=http://username:password@proxy:port

Then run pip

sudo -E pip3 install {packageName}