74

I am trying to run a script that installs pip: get-pip.py 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:

C:\SetupFiles>python get-pip.py
Downloading/unpacking pip
  Cannot fetch index base URL http://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement pip
No distributions at all found for pip
Rolando
  • 44,077
  • 84
  • 230
  • 353

6 Answers6

138

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 doesn't 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 it's installed, use:

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

From the pip man page:

--proxy
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.

Ben Burns
  • 14,172
  • 3
  • 28
  • 54
  • Your answer appears to assume pip is already installed, I have not successfully installed pip yet. Instrucutions say to run the get-pip.py script, but I am getting connection timeout, which is what I am having troubles with. – Rolando Jul 30 '12 at 18:11
  • @Damascusi, would you mind telling me if that env var worked for the get-pip script so I can update the answer appropriately? – Ben Burns Feb 03 '13 at 22:20
  • @BenBurns your solution requires easy_install to be installed, however I need a proxy to install that aswell... – youR.Fate Mar 31 '14 at 08:39
  • I tired installing it, with http_proxy and https_proxy set, but I get the error `(407) Proxyauthentifizierung erforderlich`, since our proxy uses usernames and passwords. I tried setting `http_proxy` and `https_proxy` using the `username:password@proxy` notation, but I still got the error. – youR.Fate Mar 31 '14 at 08:46
  • Do you know what kind of authentication your proxy requires? I think the only type of proxy authentication supported here will be http digest or http basic (as supported by the user:pass encoding in the url). The best solution I can suggest is to run a local proxy (such as privoxy) bound to the loopback interface (so you can only connect to it from your own machine) which in turn hands requests off to your true proxy (and therefore manages auth for you) – Ben Burns Mar 31 '14 at 09:33
  • Also, there are now quite a few ways to install pip as compared to when this question was asked/answered. You might do better to use a more "offline" install method. – Ben Burns Mar 31 '14 at 09:35
  • 1
    I was successful in installing with get-pip.py behind a proxy - even with an ssh tunnel into the server from a jump server. `export https_proxy=https://localhost:18080 ; export http_proxy=http://localhost:18080 ; export ftp_proxy=$http_proxy` then `python get-pip.py` – sastorsl May 21 '14 at 14:21
  • Thanks a ton, I've updated my answer accordingly and upvoted yours below! – Ben Burns Jun 11 '14 at 06:32
  • Does `set http_proxy=http://proxy.myproxy.com` reflect the proxy globally in the system or to a specific directory only? – cs1193 Jun 30 '15 at 09:29
  • @cs1193 the proxy will be set for all subsequent applications which are launched from that particular shell – niid Sep 28 '19 at 16:26
10

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 : http://www.leg.uct.ac.za/howtos/use-isa-proxies

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

2 To use the cntlm local proxy, exec:

pip install --proxy localhost:3128 pygments
eugenevd
  • 723
  • 6
  • 19
5

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

Adrian W
  • 3,295
  • 10
  • 30
  • 36
1

You can try downloading the Windows binaries for pip from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip.

For using pip to download other modules, see @Ben Burn's answer.

Community
  • 1
  • 1
David C
  • 6,461
  • 4
  • 46
  • 64
1

For installing pip with get-pip.py behind a proxy I went with the steps below. My server was even behind a jump server.

From the jump server:

ssh -R 18080:proxy-server:8080 my-python-server

On the "python-server"

export https_proxy=https://localhost:18080 ; export http_proxy=http://localhost:18080 ; export ftp_proxy=$http_proxy
python get-pip.py

Success.

sastorsl
  • 1,583
  • 11
  • 16
1
cd C:\Python34\Scripts

set HTTP_PROXY= DOMAIN\User_Name:Passw0rd123@PROXY_SERVER_NAME_OR_IP:PORT#

set HTTP_PROXY= DOMAIN\User_Name:Passw0rd123@PROXY_SERVER_NAME_OR_IP:PORT#

pip.exe install PackageName
Michał Perłakowski
  • 70,955
  • 24
  • 137
  • 155