How to get pip to work behind a proxy server

83

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:[email protected]:port TwitterApi

But I still get the same error. How do I get pip to work behind a proxy server.

This question is tagged with python proxy pip

~ Asked on 2013-09-29 16:23:23

The Best Answer is


111

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

You should use the following:

pip install --proxy http://user:[email protected]: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:[email protected]:port

~ Answered on 2013-12-28 19:18:12


30

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

~ Answered on 2014-04-16 07:56:07


Most Viewed Questions: