28

I used to set up environment evariables http_proxy and https_proxy (with user + password) in the past to use Pip (on Windows) behind a corporate proxy. But recently I needed to tell Pip to use a proxy without setting up environment variables as this conflicted with git configuration in combination with SSL Certificates which I get to work only by removing environment variables for proxy.

Fortunately you can configure PIP with an pip.ini file as described here: https://pip.pypa.io/en/stable/user_guide/#config-file

The detailed answer to my own question follows below.

Wlad
  • 2,866
  • 3
  • 28
  • 42

5 Answers5

49

Here are the steps how to configure proxy (with auth.) in pip's config file (pip.ini)

  1. (if it does not already exist) Create a folder named 'pip' and inside it a file named 'pip.ini' as described here: https://pip.pypa.io/en/stable/user_guide/#config-file (location an name may differ per platform - e.g. on Windows it's %APPDATA%\pip\pip.ini)
  2. edit pip.ini file and add

    [global]
    proxy = http://user:password@proxy_name:port
    
  3. That's it!

Example for proxy with authentification (user + password):

proxy = http://butch:secret@proxyname:1234

proxyname can be an IP adress, too

Example for proxy without auth.:

proxy = http://proxyname:1234

Wlad
  • 2,866
  • 3
  • 28
  • 42
  • Thanks, this solved my problem... I didn't need username or password, just the proxy IP. – James McCorrie Oct 11 '18 at 14:03
  • In cmd, do I just need to write "pip install requests" for example? Will the ini be automatically checked? I can't seem to get it working. – Rob Blagg Nov 09 '18 at 12:45
  • 4
    In Windows 10, the path will be: C:\Users\\AppData\Roaming\pip\pip.ini – Shashank Jan 17 '19 at 13:05
  • 2
    this works to me but naming the conf file `pip.conf` instead of `pip.ini` as the docs say (using ubuntu 18.04) – Yasiel Cabrera Sep 30 '20 at 13:23
  • exactly, what does the `pip install...` command look like now after setting up this configuration file? – TMOTTM Oct 08 '21 at 13:24
  • @TMOTTM `pip install ...` will not change. e.g. `pip install robotframework`. If u do not setup a pip.conf (or pip.ini) you will have to provide proxy info as cli option whenever you call pip (see the other answers below), e.g. `pip install robotframework --proxy https://user_name:password@proxyname:port` – Wlad Oct 14 '21 at 07:50
21

A little easier with:

pip config set global.proxy http://{host}:{port}

and it will persist the setting automagically

Writing to C:\Users\{username}\AppData\Roaming\pip\pip.ini
Anwar Husain
  • 1,414
  • 14
  • 19
  • 2
    I have used this after activating my virtualenv with pyenv. A configuration has been created just for this environment and it solved my issue with corp proxy. Thank you. – Asmoox Nov 23 '21 at 10:31
14

In order to add a proxy option in the terminal the following line solved the problem for me:

pip install package_name_here --proxy https://user_name:password@proxyname:port
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
crunchyminion
  • 141
  • 1
  • 3
4

You need to set proxy option while installing the package. example:

pip install --proxy userid:password@proxy.domain.com:yourport
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
2

If package that you are trying to install has dependencies it's best to create pip.ini for system wide configuration, in windows you can do this in powershell:

mkdir c:\programdata\pip\
new-item c:\programdata\pip\pip.ini

and add this to your pip.ini

[global]
proxy = http://domain\user:pwd@proxy_hostname_or_ip:port 

and then everything should work fine, as HTTP_PROXY variable didn't work for me.

Make sure to save file as ansi or windows1252 in VSCode as UTF files are not read properly.

knile
  • 318
  • 3
  • 15
  • Pip uses variables with prefix `PIP_`. The rest is the option name in uppercase with underscores. On Unix: `export PIP_PROXY=...` on Windows: `set PIP_PROXY=...` --- See https://pip.pypa.io/en/stable/user_guide/#environment-variables – pabouk - Ukraine stay strong Apr 01 '21 at 07:39