101

I have Python 2.7.8 installed on my Windows 7 machine, which comes with pip already pre-installed. I'm able to successfully install new packages from pip and now I need to add a custom repository URL to the install list of pip.

To do so I need to modify pip.ini which is in %APPDATA%\pip\pip.ini, according to the Official Manual. However, there is no pip folder anywhere (not in Roaming, not in Local, not in LocalLow) nor is there a PyPa folder in: C:\ProgramData\PyPA\pip\pip.conf

Could you tell me where I should search for pip.ini? How can I add a foreign repo to the install list?

swimfar2
  • 103
  • 8
Bryksin
  • 2,322
  • 3
  • 19
  • 31

14 Answers14

152

Instead of checking a list of well-known locations, you can ask pip to list the valid locations:

pip config -v list

Fun fact

On the same machine, with the same pip version, the valid locations can vary based on the actual Python version.

Environment: Win 7 x64, the HOME environment variable is set to D:\Home

Python 3.7.3:

> pip config -v list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'D:\Home\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'C:\Python37\pip.ini'

Python 3.8.0:

> pip config -v list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'C:\Python38\pip.ini'
alexandrul
  • 12,856
  • 13
  • 72
  • 99
  • 1
    Won't `pip config -v list` or `pip config --verbose list` do? – dumbledad Apr 09 '20 at 18:36
  • @dumbledad I don't have a Windows machine at hand, so I can't check. On Linux it works with `-v` – alexandrul Apr 10 '20 at 10:49
  • 1
    @dumbledad thank you, it's working fine on Windows too – alexandrul Apr 10 '20 at 18:49
  • 2
    This is really helpful and works across platforms, thank you. – Vasantha Ganesh Aug 07 '20 at 10:39
  • 1
    Thank you. This worked. Instead of copying files blindly at `%APPDATA%\pip\pip.ini`, check which pip path a certain environment is using and create a `pip.ini` file at that location. – Akash Gandhi Sep 13 '22 at 17:51
  • FYI, this command doesn't seem to work if the files don't exist -- i.e. if you don't have any of the files, this command doesn't produce any output. Instead, to see which files *would* be used (even if they don't currently exist), you can use this command instead: `pip config debug` – Seth Mar 14 '23 at 20:43
  • @Seth it's still working for me, as intended, showing the valid locations that would be checked (even if the actual files don't exist yet). The `-v` is mandatory for this purpose. Win 10 x64, Python 3.11.2 – alexandrul Mar 15 '23 at 22:50
  • @alexandrul Weird, I don't know why it didn't work for me then (I tried both with and without the `-v` flag). I tried it on Windows 10 as well, running Python 3.9.1 and Pip 21.2.4, and got the same result (no output) regardless of which terminal I ran the command in (Git Bash, Powershell or cmd). – Seth Mar 16 '23 at 20:16
  • 1
    @alexandrul Update: After upgrading Pip from `21.2.4` to the latest version (`23.0.1`), your command (`pip config -v list`) worked as described above – Seth Mar 21 '23 at 19:39
71

Finally got it sorted.

Apparently for Windows users pip.ini config file is not created, however can be added manually!

just create new %APPDATA%\pip\pip.ini and content of custom repository:

[install]
find-links = https://<login>:<password>@your.repo.com/custom/url

Reference: https://pip.pypa.io/en/stable/user_guide/#config-file

Franklin Yu
  • 8,920
  • 6
  • 43
  • 57
Bryksin
  • 2,322
  • 3
  • 19
  • 31
  • On python 3.6 it works for me from C:\ProgramData\pip\pip.conf only. – iTayb Jan 01 '18 at 15:16
  • 4
    Using Python 3.8, I had to manually create the `pip` folder and the `pip.ini` file as well. I used it for our corporate proxy settings. – Valentin Grégoire Mar 10 '20 at 20:41
  • @ValentinGrégoire Where did you create your pip folder and how did you ensure it was picked up when launching? _pip config -v list_ lists a selection of variants. – QHarr Apr 17 '20 at 07:39
  • @QHarr, I created it at the sugested place in this answer (`%APPDATA%\pip\pip.ini`). As for getting picked up, I prayed for it, and it worked. – Valentin Grégoire Apr 21 '20 at 13:37
  • 1
    @QHarr See the answer of alexandrul. You can for example check with an erroneous pip.ini that has no [install] section header. I have installed Anaconda for my user only. Then, both the 2x`user variant` and the `anaconda variant` work (error thrown). I have not checked the `global variant` since I have a user installation. – questionto42 Aug 10 '20 at 17:31
21

A bit late, but for reference: Try adding the pip.ini file in %USERPROFILE%\pip\pip.ini (usually: C:\Users\<username>\pip\pip.ini).

Moshe Zvi
  • 437
  • 4
  • 8
  • 1
    Putting the pip folder directly in the user folder is the what worked for me on Windows 7 and Windows 10 using Python 3. Thanks for the tip, Moshe. – wyattis Mar 02 '17 at 16:55
18

On windows pip.exe looks for "pip.ini" in this order:

C:\ProgramData\pip\pip.ini
C:\Users\<username>\pip\pip.ini
C:\Users\<username>\AppData\Roaming\pip\pip.ini
Sirmabus
  • 636
  • 8
  • 8
  • I'm not sure this is still the case. On my Win7 machine with py3.6.3 when I tried adding `[list] ...format=columns` it only took effect when placed in APPDATA. – matt wilkie Nov 26 '17 at 18:34
  • 1
    That was for 2.7, so you could be right. I had used sysinternals procmon to watch Python.exe was doing; searching in order for access to "pip.ini". Anyone can do the same to ensure the order is still the same: https://learn.microsoft.com/en-us/sysinternals/downloads/procmon – Sirmabus Nov 20 '18 at 20:49
  • I can confirm part of it. I have put an erroneous pip.ini both in `C:\Users\\pip\pip.ini` and in `%APPDATA%\pip\pip.ini`. Then `pip config -v list` reported username\pip directory (I had forgotten a section header). This shows that the the username\pip directory comes before the appdata\pip directory. – questionto42 Aug 10 '20 at 17:12
17

It's been 7 years, and I think there's now a better answer for most people -- but it does depend on version of pip. For the most recent pips I'm using:

    $ pip config -v debug

lists where it's looking and you can decide which location is most useful for what you've got in mind. It does look like a fairly recent change: On a year-old docker image I had with pip 20.1 I got "ERROR: Need an action (edit, get, list, set, unset) to perform." On that system, pip config -v list gave a list of files it would try, this is supposed to be 'global', 'user' or 'site' variants of pip.ini locations.

For Windows 10, for pip 21.2.4 on both 3.9.6 and 3.6.8, I get response below with pip config -v debug, while pip config -v list is silent (unless a pip.ini is found).

global:
  C:\ProgramData\pip\pip.ini, exists: False
site:
  c:\py\myvenv\pip.ini, exists: False
user:
  C:\Users\myname\pip\pip.ini, exists: False
  C:\Users\myname\AppData\Roaming\pip\pip.ini, exists: False

From a downloaded image I got from dockerhub in June 2021 with pip 21.2.2 and python 3.6.10:

 pip config -v debug
 env_var:
 env:
 global:
   /etc/xdg/pip/pip.conf, exists: False
   /etc/pip.conf, exists: True
 global.extra-index-url: http://trynexs:8081/repository/repo_group/simple
 site:
   /usr/local/pip.conf, exists: False
 user:
   /home/tanhauser/.pip/pip.conf, exists: False
   /home/tanhauser/.config/pip/pip.conf, exists: False
Levin Magruder
  • 1,905
  • 18
  • 26
8

Pip changed the location of the config file in windows starting in pip 6.0 the pip config docs explain the location of the config files as follows.

pip --version >= 6 (as of version 18.1 hasn't changed again yet)

%APPDATA%\pip\pip.ini

pip --version < 6

%HOME%\pip\pip.ini

Inside a virtual env

%VIRTUAL_ENV%\pip.ini

Site-wide win7+ (same as of win10)

C:\ProgramData\pip\pip.ini

Site-wide winxp (note windows vista side wide not supported)

C:\Documents and Settings\All Users\Application Data\pip\pip.ini

NOTE: If multiple configuration files are found by pip then they are combined in the following order:

  1. The site-wide file is read
  2. The per-user file is read
  3. The virtualenv-specific file is read

Also pip added a config command starting in pip 10.

pip config --help
Pykler
  • 14,565
  • 9
  • 41
  • 50
4

I know this is a bit late, however, this post is high on the rankings when searching. Inside a virtual environment pip.ini can also be in the root of the virtual environment. From the docs and https://pip.pypa.io/en/stable/user_guide/?highlight=pip.ini#configuration

Inside a virtualenv:

On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
AMG
  • 1,606
  • 1
  • 14
  • 25
4

All the answers are partially wrong and right. It depends on how your system is configured. The only way (for me) to find out was to patch site-packages/pip/locations.py at the point where site_config_files is assigned (around line 120 for pip 9.0.1)

print('########## ' + str(site_config_files))

and then run pip search foo

On my system it printed ########## ['C:\\ProgramData\\pip\\pip.ini'], of which location I assumed I could not create/edit. But it just worked.

Btw, for my system %APPDATA% points to C:\Users\MYUSER\AppData\Roaming, which is not looked at when running pip on my system.

Wolfgang Kuehn
  • 12,206
  • 2
  • 33
  • 46
3

Rather than guessing first check if you have any default global/local config which is read by pip with the below command:

pip config list

This will give all details of the default config loaded by python.

If the above command doesn't give any output please try to find where pip tries to find for the global config file with the below command:

pip config --editor <path to editor of your choice> edit

The above command will open the config file which pip reads by default or else it will give an error saying that the file doesn't exist.

If there's an error please go ahead and create the exact directory and file structure as show in the error. Once the file has been created please make your changes e.g.

[global]
cert = /path/to/base64/ssl/certificate.pem
proxy = http://username:password@ipaddress:port

Save the file and please try to check (the above mentioned check command) if the configs are loaded by pip or not.

For more info please follow pip config documentation

skap
  • 493
  • 4
  • 9
2

Make sure you acually have a pip.ini file, not pip.ini.txt.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Bendik Knapstad
  • 1,409
  • 1
  • 9
  • 18
  • Indeed, you may only notice this if you check your files in a terminal! -> If your config was actually picked up by pip you will also get a print of the variables specified in the config file when you tpye pip config -v list after the list of preconfigured config paths, e.g.: global.index-url='%URL%' – m_h Oct 27 '21 at 11:29
2

For Windows, python will load the config from path below. So, if pip.ini file is not exist in these paths you can create the new file by refer these path depend on environment scopes (global, user & site) that you need python execute.

  • For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
  • For variant 'user', will try loading 'C:\Users\MyName\pip\pip.ini'
  • For variant 'user', will try loading 'C:\Users\MyName\AppData\Roaming\pip\pip.ini'
  • For variant 'site', will try loading 'c:\python39-32\pip.ini'

By the way, you can check the paths as above by pip config -v list

1

For me (Windows 8, pip 9.0.1, python 3.5.3), the correct path was

c:\Users\<UserName>\.pypirc      <- sic!, even on windows
Tommy
  • 739
  • 8
  • 24
1

Windows 10:

I had to create 'pip' directory inside

C:\Users\UserName\AppData\Roaming\

then create pip.ini file inside that 'pip' directory:

C:\Users\<username>\AppData\Roaming\pip\pip.ini

No other location worked for me.

kujaw
  • 313
  • 1
  • 3
  • 18
0

On a Windows 10 machine with multiple users I used this:

c:\users\all users\pip\pip.ini

Using pip version 22.3.1 with python version 3.10.4..

user8128167
  • 6,929
  • 6
  • 66
  • 79