Python pip.conf 不注意受信任的主机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45337029/
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-08-19 16:55:54  来源:igfitidea点击:

pip.conf not paying attention to trusted-host

pythonpippypi

提问by celestialorb

I have my pip.conffile as follows:

我的pip.conf文件如下:

[global]
trusted-host = <private IP>
extra-index-url = http://<private IP>/pypi

However, whenever I try to install a package (just a test package) from the private pypi repo, I receive an error that instructs me to add --trusted-host <private IP>. If I do, I can successfully install the package, so I know that pipis reading the pip.conffile. Why isn't it respecting the trusted-hostconfig? I've triple checked that the IPs match in the config file.

但是,每当我尝试从私有 pypi 存储库安装一个包(只是一个测试包)时,我都会收到一个错误,指示我添加--trusted-host <private IP>. 如果我这样做,我可以成功安装该软件包,因此我知道pip正在读取该pip.conf文件。为什么不尊重trusted-host配置?我已经三重检查了配置文件中的 IP 是否匹配。

Several blogs and cursory searches of Google seem to suggest that it should. (https://pseudoscripter.wordpress.com/2016/05/07/pip-the-repository-located-at-some-ip-is-not-a-trusted-or-secure-host-and-is-being-ignored/)

谷歌的几个博客和粗略搜索似乎表明它应该。( https://pseudoscripter.wordpress.com/2016/05/07/pip-the-repository-located-at-some-ip-is-not-a-trusted-or-secure-host-and-is-being -忽略/)

回答by gmauch

Couldn't this be a problem of different pip.conf having different configurations?According to the official docs:

这不会是不同pip.conf配置不同的问题吧?根据官方文档

The names and locations of the configuration files vary slightly across platforms. You may have per-user, per-virtualenv or site-wide (shared amongst all users) configuration.

配置文件的名称和位置因平台而异。您可能有每个用户、每个虚拟环境或站点范围(在所有用户之间共享)的配置。

  • On Unix the default configuration file is: $HOME/.config/pip/pip.confwhich respects the XDG_CONFIG_HOMEenvironment variable.
  • There is also a legacy per-user configuration file which is also respected, and is located at $HOME/.pip/pip.confon Unix and macOS.
  • Inside a virtualenv, on Unix and macOS the file is $VIRTUAL_ENV/pip.conf
  • Site-wide, on Unix the file may be located in /etc/pip.conf. Alternatively it may be in a "pip" subdirectory of any of the paths set in the environment variable XDG_CONFIG_DIRS(if it exists), for example /etc/xdg/pip/pip.conf.
  • 在 Unix 上,默认配置文件是:$HOME/.config/pip/pip.conf,它尊重XDG_CONFIG_HOME环境变量。
  • 还有一个旧的每用户配置文件也受到尊重,它位于 Unix 和 macOS 上的$HOME/.pip/pip.conf
  • 在 virtualenv 中,在 Unix 和 macOS 上,文件是$VIRTUAL_ENV/pip.conf
  • 在站点范围内,在 Unix 上,该文件可能位于/etc/pip.conf 中。或者,它可能位于环境变量XDG_CONFIG_DIRS(如果存在)中设置的任何路径的“pip”子目录中,例如/etc/xdg/pip/pip.conf

回答by celestialorb

Copied my pip.conf from $HOME/.pip/pip.conf to /etc/pip.conf and it worked!

将我的 pip.conf 从 $HOME/.pip/pip.conf 复制到 /etc/pip.conf 并且它起作用了!

回答by planteater

To check which config file is being looked at run: pip config --editor pathtoeditorofyourchoice edit, this will open the linked ini file. If it doesnt exist, the Editor (notepad++) will state that there is no file at a specific path <-- and there is your path where you should place the file then.

要检查正在查看哪个配置文件 run: pip config --editor pathtoeditorofyourchoice edit,这将打开链接的 ini 文件。如果它不存在,编辑器 (notepad++) 将声明在特定路径 <-- 没有文件,然后有你应该放置文件的路径。

Also consider as stated here (https://pip.pypa.io/en/stable/user_guide):

还要考虑如下所述(https://pip.pypa.io/en/stable/user_guide):

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

Each file read overrides any values read from previous files, so if the global timeout is specified in both the site-wide file and the per-user file then the latter value will be used.

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

The site-wide file is read
The per-user file is read
The virtualenv-specific file is read

每个文件读取都会覆盖从先前文件读取的任何值,因此如果在站点范围的文件和每个用户的文件中都指定了全局超时,则将使用后一个值。

The docs also say:

文档还说:

You can set a custom path location for this config file using the environment variable PIP_CONFIG_FILE.

您可以使用环境变量 PIP_CONFIG_FILE 为该配置文件设置自定义路径位置。

However, running the upper command with this environment variable set up lead to a

但是,使用此环境变量设置运行上层命令会导致

Fatal Internal error [id=2]. Please report as a bug.