可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I got Python 2.7.8 installed on my Win7 machine, which comes with pip already pre-installed.
I'm successfully able to install new packages from pip and now I need to add 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 are no pip
folder anywhere (not in Roaming
, not in Local
, not in LocalLow
)
nor there exists PyPa
folder in: C:\ProgramData\PyPA\pip\pip.conf
Could you tell me where do i search for pip.ini
? how to add foreign repo to the install list?
回答1:
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
回答2:
A bit late, but for reference:
Try adding the pip.ini file in %USERPROFILE%\pip\pip.ini
(usually: C:\Users\<username>\pip\pip.ini
).
回答3:
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'
回答4:
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
回答5:
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:
- The site-wide file is read
- The per-user file is read
- The virtualenv-specific file is read
Also pip added a config command starting in pip 10.
pip config --help
回答6:
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.
回答7:
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
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
回答8:
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
回答9:
For me (Windows 8, pip 9.0.1, python 3.5.3), the correct path was
c:\Users\<UserName>\.pypirc <- sic!, even on windows
回答10:
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.
回答11:
Make sure you acually have a pip.ini
file, not pip.ini.txt
.