Python - 在 Windows 中找不到 pip.ini 或 pip.conf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28278207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:57:29  来源:igfitidea点击:

Python - cant find pip.ini or pip.conf in Windows

windowspython-2.7configurationpip

提问by Briksins

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

我在我的 Win7 机器上安装了 Python 2.7.8,它已经预装了 pip。
我成功地能够从 pip 安装新软件包,现在我需要将自定义存储库 url 添加到 pip 的安装列表中

To do so I need to modify pip.iniwhich is in %APPDATA%\pip\pip.iniaccording to the Official Manual
However there are no pipfolder anywhere (not in Roaming, not in Local, not in LocalLow) nor there exists PyPafolder in: C:\ProgramData\PyPA\pip\pip.conf

为此,我需要根据官方手册修改pip.ini其中的内容 但是任何地方都没有文件夹(不在,不在,不在),也不存在文件夹:%APPDATA%\pip\pip.ini
pipRoamingLocalLocalLowPyPaC:\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?

你能告诉我在哪里搜索pip.ini吗?如何将外部存储库添加到安装列表中?

回答by Briksins

Finally got it sorted.

终于整理好了

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

显然没有为 Windows 用户pip.ini创建配置文件,但是可以手动添加!

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

只需创建%APPDATA%\pip\pip.ini自定义存储库的新内容和内容:

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

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

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

回答by Moshe Zvi

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

有点晚了,但仅供参考:尝试将 pip.ini 文件添加到%USERPROFILE%\pip\pip.ini(通常是:)C:\Users\<username>\pip\pip.ini

回答by alexandrul

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

您可以要求pip列出有效位置,而不是检查众所周知的位置列表:

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.

在同一台机器上,使用相同的 pip 版本,有效位置可能因实际 Python 版本而异。

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

环境:Win 7 x64,HOME环境变量设置为D:\Home

Python 3.7.3:

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:

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'

回答by Sirmabus

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

在 Windows 上,pip.exe 按以下顺序查找“pip.ini”:

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

回答by Pykler

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

皮普在窗口更改配置文件的位置开始在PIP 6.0PIP配置文档解释了配置文件的位置如下。

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

pip --version >= 6 (从 18.1 版本开始,还没有再次更改)

%APPDATA%\pip\pip.ini

pip --version < 6

pip --version < 6

%HOME%\pip\pip.ini

Inside a virtual env

在虚拟环境中

%VIRTUAL_ENV%\pip.ini

Site-wide win7+ (same as of win10)

全站win7+(同win10)

C:\ProgramData\pip\pip.ini

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

站点范围的 winxp(注意 windows vista sidewide 不支持)

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:

注意:如果 pip 找到多个配置文件,则它们按以下顺序组合:

  1. The site-wide file is read
  2. The per-user file is read
  3. The virtualenv-specific file is read
  1. 读取站点范围的文件
  2. 读取每个用户的文件
  3. 读取 virtualenv 特定文件

Also pip added a config command starting in pip 10.

pip 还添加了一个从 pip 10 开始的配置命令。

pip config --help

回答by Wolfgang Kuehn

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

所有的答案都是部分错误和正确的。这取决于您的系统是如何配置的。(对我来说)找出答案的唯一方法是site-packages/pip/locations.pysite_config_files指定的位置打补丁 (pip 9.0.1 大约在第 120 行)

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

打印('##########' + str(site_config_files))

and then run pip search foo

然后运行 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.

在我的系统上,它打印了########## ['C:\\ProgramData\\pip\\pip.ini'],我认为我无法创建/编辑的位置。但它只是奏效了。

Btw, for my system %APPDATA% points to C:\Users\MYUSER\AppData\Roaming, which is not looked atwhen running pipon my system.

顺便说一句,对于我的系统 %APPDATA% 指向C:\Users\MYUSER\AppData\Roaming,在我的系统上运行时不会查看pip

回答by AMG

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

我知道这有点晚了,但是,这篇文章在搜索时排名很高。在虚拟环境中 pip.ini 也可以在虚拟环境的根目录中。从文档

Inside a virtualenv:

On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini

回答by skap

Rather than guessing first checkif you have any default global/local configwhich is read by pipwith the below command:

而不是猜测首先检查您是否有任何默认的全局/本地配置,这些配置pip使用以下命令读取:

pip config list

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

这将提供由 python 加载的默认配置的所有详细信息。

If the above command doesn't give any outputplease try to find where pip tries to find for the global configfile with the below command:

如果上面的命令没有给出任何输出,请尝试使用以下命令查找 pip 尝试为全局配置文件查找的位置:

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.

上面的命令将打开 pip 默认读取的配置文件,否则会报错说该文件不存在。

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.

保存文件,请尝试检查(上面提到的检查命令)是否通过 pip 加载了配置。

For more info please follow pip config documentation

有关更多信息,请遵循pip 配置文档

回答by Tommy

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

对我来说(Windows 8,pip 9.0.1,python 3.5.3),正确的路径是

c:\Users\<UserName>\.pypirc      <- sic!, even on windows

回答by kujaw

Windows 10:

视窗 10:

I had to create 'pip' directory inside

我必须在里面创建“pip”目录

C:\Users\UserName\AppData\Roaming\

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

然后在“pip”目录中创建 pip.ini 文件:

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

No other location worked for me.

没有其他位置对我有用。