【问题标题】:Which PyPI index does Pip point to?Pip 指向哪个 PyPI 索引?
【发布时间】:2021-01-06 15:33:42
【问题描述】:

Ubuntu 20.04.1 LTS | Python 3.8.5 |点 20.0.2(通过 python3-pip)

我不小心用自定义索引覆盖了笔记本电脑中的全局 PyPI 索引。 (它的目的是仅在虚拟环境中设置。如果它有用,我使用的是 AWS CodeArtifact。)

我是在运行 pip3 config -v list 并看到 global.index-url 分配了另一个 URL 以及 ~/.config/.pip/pip.conf 列出相同的 URL 之后说的。

为了解决问题,我做了以下事情:

  1. 将 pip3 的 global.index-url 设置为 "https://pypi.python.org/pypi",但是当我进行测试以查看它是否有效时,它在尝试在虚拟环境中安装 requests(使用它的 pip)时中途停止并说某些依赖项不是满意。

  2. 然后我将~/.config/.pip 移动到备份中,卸载了python3-pip 并重新安装了软件包,希望重新编写配置。虽然没有创建新的~/config/.pip,但我能够毫无问题地将请求安装到虚拟环境中。

我的困惑源于我不知道 pip 是从哪里来的。下面列出的文件都不存在!

$ pip config -v list
For variant 'global', will try loading '/etc/xdg/xdg-ubuntu/pip/pip.conf'
For variant 'global', will try loading '/etc/xdg/pip/pip.conf'
For variant 'user', will try loading '/home/<user>/.pip/pip.conf'
For variant 'user', will try loading '/home/<user>/.config/pip/pip.conf'
For variant 'site', will try loading '/home/<user>/test_env/venv/pip.conf'

当我在虚拟环境停用的情况下使用 pip3 时,输出略有不同。

$ pip3 config -v list
For variant 'global', will try loading '/etc/xdg/xdg-ubuntu/pip/pip.conf'
For variant 'global', will try loading '/etc/xdg/pip/pip.conf'
For variant 'user', will try loading '/home/<user>/.pip/pip.conf'
For variant 'user', will try loading '/home/<user>/.config/pip/pip.conf'
For variant 'site', will try loading '/usr/pip.conf'

谁能告诉我这一切是如何运作的?

【问题讨论】:

  • 对我来说太难了。只需在使用 pip 时嗅探网卡上的流量,看看它的去向
  • Doesn't pip 在执行时显示它的目标,即 pip install package X ??
  • 不,它没有。我还确保它没有从缓存中挑选东西 (--no-cache-dir)。但它没有说明从哪里下载包。
  • pip install paxckageX --verbose
  • 找到 . -name 'pip.conf' ---> 有没有显示?

标签: python ubuntu pip


【解决方案1】:

https://pypi.org/simple/packageX

让我知道它是否正确?

使用

    pip install paxckageX --verbose

现在不确定它是否正确,但在这里:

Python can't find the file pip.conf

这里

pip user guide Configuration

Configuration
Config file

pip allows you to set all command line option defaults in a standard ini style config file.

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

Per-user:

    On Unix the default configuration file is: $HOME/.config/pip/pip.conf which respects the XDG_CONFIG_HOME environment variable.

    On macOS the configuration file is $HOME/Library/Application Support/pip/pip.conf if directory $HOME/Library/Application Support/pip exists else $HOME/.config/pip/pip.conf.

    On Windows the configuration file is %APPDATA%\pip\pip.ini.

There is also a legacy per-user configuration file which is also respected. To find its location:

    On Unix and macOS the configuration file is: $HOME/.pip/pip.conf

    On Windows the configuration file is: %HOME%\pip\pip.ini

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

Inside a virtualenv:

    On Unix and macOS the file is $VIRTUAL_ENV/pip.conf

    On Windows the file is: %VIRTUAL_ENV%\pip.ini

Global:

    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.

    On macOS the file is: /Library/Application Support/pip/pip.conf

    On Windows XP the file is: C:\Documents and Settings\All Users\Application Data\pip\pip.ini

    On Windows 7 and later the file is hidden, but writeable at C:\ProgramData\pip\pip.ini

    Global configuration is not supported on Windows Vista.

The global configuration file is shared by all Python installations.

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

    The global 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 global file and the per-user file then the latter value will be used.

The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (--index-url) and set the HTTP timeout (--default-timeout) to 60 seconds your config file would look like this:

[global]
timeout = 60
index-url = https://download.zope.org/ppix

Each subcommand can be configured optionally in its own section so that every global setting with the same name will be overridden; e.g. decreasing the timeout to 10 seconds when running the freeze (pip freeze) command and using 60 seconds for all other commands is possible with:

[global]
timeout = 60

[freeze]
timeout = 10

Boolean options like --ignore-installed or --no-dependencies can be set like this:

[install]
ignore-installed = true
no-dependencies = yes

To enable the boolean options --no-compile, --no-warn-script-location and --no-cache-dir, falsy values have to be used:

[global]
no-cache-dir = false

[install]
no-compile = no
no-warn-script-location = false

For options which can be repeated like --verbose and --quiet, a non-negative integer can be used to represent the level to be specified:

[global]
quiet = 0
verbose = 2

It is possible to append values to a section within a configuration file such as the pip.ini file. This is applicable to appending options like --find-links or --trusted-host, which can be written on multiple lines:

[global]
find-links =
    http://download.example.com

[install]
find-links =
    http://mirror1.example.com
    http://mirror2.example.com

trusted-host =
    mirror1.example.com
    mirror2.example.com

This enables users to add additional values in the order of entry for such command line arguments.
Environment Variables

pip’s command line options can be set with environment variables using the format PIP_<UPPER_LONG_NAME> . Dashes (-) have to be replaced with underscores (_).

For example, to set the default timeout:
Unix/macOS

export PIP_DEFAULT_TIMEOUT=60

Windows

This is the same as passing the option to pip directly:
Unix/macOS

python -m pip --default-timeout=60 [...]

Windows

For command line options which can be repeated, use a space to separate multiple values. For example:
Unix/macOS

export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"

Windows

is the same as calling:
Unix/macOS

python -m pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com

Windows

Options that do not take a value, but can be repeated (such as --verbose) can be specified using the number of repetitions, so:

export PIP_VERBOSE=3

is the same as calling:

pip install -vvv

Note

Environment variables set to be empty string will not be treated as false. Please use no, false or 0 instead.
Config Precedence

Command line options have precedence over environment variables, which have precedence over the config file.

Within the config file, command specific sections have precedence over the global section.

Examples:

    --host=foo overrides PIP_HOST=foo

    PIP_HOST=foo overrides a config file with [global] host = foo

    A command specific section in the config file [<command>] host = bar overrides the option with same name in the [global] config file section

【讨论】:

  • 谢谢。是的,它似乎正在查找 pypi.org/simple,尽管我没有发现它在通常的位置进行了配置。我怀疑发生的事情是,使用 AWS CodeArtifact 的命令最终以某种方式创建了全局配置文件,然后优先于通常的索引。 (作为比较,我的 WSL 20.04 在这些位置也没有配置文件。)非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2014-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多