How to set an HTTP proxy in Python 2.7?

How to set an HTTP proxy in Python 2.7?

It looks like get-pip.py has been updated to use the environment variables http_proxy and https_proxy.

Windows:

set http_proxy=http://proxy.myproxy.com
set https_proxy=https://proxy.myproxy.com
python get-pip.py

Linux/OS X:

export http_proxy=http://proxy.myproxy.com
export https_proxy=https://proxy.myproxy.com
sudo -E python get-pip.py

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

Windows:

set http_proxy=http://proxy.myproxy.com
set https_proxy=https://proxy.myproxy.com
easy_install pip

Linux/OS X:

export http_proxy=http://proxy.myproxy.com
export https_proxy=https://proxy.myproxy.com
sudo -E easy_install pip

Then once its installed, use:

pip install --proxy=user:[email protected]:port packagename

From the pip man page:

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

On my network just setting http_proxy didnt 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 : http://www.leg.uct.ac.za/howtos/use-isa-proxies

Instead of student number, youd put your domain username

2 To use the cntlm local proxy, exec:

pip install --proxy localhost:3128 pygments

How to set an HTTP proxy in Python 2.7?

You can install pip (or any other package) with easy_install almost as described in the first answer. However you will need a HTTPS proxy, too. The full sequence of commands is:

set http_proxy=http://proxy.myproxy.com
set https_proxy=http://proxy.myproxy.com
easy_install pip

You might also want to add a port to the proxy, such as http{s}_proxy=http://proxy.myproxy.com:8080

Leave a Reply

Your email address will not be published. Required fields are marked *