Python: Using pip with a squid proxy

python-logoIn a production datacenter it would not be uncommon for internet access to be limited to domains whitelisted on a web proxy such as Squid.  If this is the case, and you are using pip to install packages, then you will need to:

  • Have your Squid administrators whitelist pypi.python.org
  • Add the “–proxy” switch when invoking pip for installs
sudo apt-get install python-dev python-pip libyaml-dev

sudo pip install pyaml --upgrade --proxy http://squidproxy:3128

There are reports of this not working on certain sytems/versions, in which case you can try setting the proxy through environment variables as shown below.

export http_proxy=http://squidproxy:3128
export https_proxy=http://squidproxy:3128

sudo pip install pyaml --upgrade

REFERENCES

https://stackoverflow.com/questions/14149422/using-pip-behind-a-proxy