How to set an HTTP proxy in Python 2.7?


I am trying to run a script that installs pip: and am getting a connection timeout due to my network being behind an HTTP proxy. Is there some way I could configure an HTTP proxy in my Python 2.7 installation to be able to install what I am trying to install?

Note: I am using Windows. Below is the error I am getting:

Downloading/unpacking pip
  Cannot fetch index base URL
  Could not find any downloads that satisfy the requirement pip
No distributions at all found for pip
7/30/2012 6:12:20 PM

Accepted Answer

It looks like has been updated to use the environment variables http_proxy and https_proxy.


set http_proxy=
set https_proxy=

Linux/OS X:

export http_proxy=
export https_proxy=
sudo -E python

However if this still doesn't work for you, you can always install pip through a proxy using setuptools' easy_install by setting the same environment variables.


set http_proxy=
set https_proxy=
easy_install pip

Linux/OS X:

export http_proxy=
export https_proxy=
sudo -E easy_install pip

Then once it's installed, use:

pip install --proxy="user:password@server:port" packagename

From the pip man page:

Have pip use a proxy server to access sites. This can be specified using "user:password@proxy.server:port" notation. If the password is left out, pip will ask for it.

6/11/2014 6:28:57 AM

On my network just setting http_proxy didn't work for me. The following points were relevant.

1 Setting http_proxy for your user wont be preserved when you execute sudo - to preserve it, do:

sudo -E yourcommand

I got my install working by first installing cntlm local proxy. The instructions here is succinct :

Instead of student number, you'd put your domain username

2 To use the cntlm local proxy, exec:

pip install --proxy localhost:3128 pygments

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow