是否有可能让pip打印出正在使用的配置? [英] Is it possible to get pip to print the configuration it is using?

查看:133
本文介绍了是否有可能让pip打印出正在使用的配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让pip打印将尝试使用的配置?出于调试目的,很高兴知道这一点:

Is there any way to get pip to print the config it will attempt to use? For debugging purposes it would be very nice to know that:

  1. config.ini文件放在正确的位置,并且pip找到了它们.
  2. 按照人们从 docs

推荐答案

10.0.x及更高版本

有一个新的pip config命令,用于列出当前配置值

There is new pip config command, to list current configuration values

pip config list

(如@wmaddox在评论中指出的)以获取pip在何处查找配置文件的列表

(As pointed by @wmaddox in comments) To get the list of where pip looks for config files

pip config list -v

Pre 10.0.x

您可以启动python控制台并执行. (如果您有virtaulenv,别忘了先激活它)

You can start python console and do. (If you have virtaulenv don't forget to activate it first)

from pip import create_main_parser
parser = create_main_parser()
# print all config files that it will try to read
print(parser.files)
# reads parser files that are actually found and prints their names 
print(parser.config.read(parser.files))

create_main_parser 是创建 parser ,pip用来从命令行读取参数(optparse)并加载配置(configparser)

create_main_parser is function that creates parser which pip uses to read params from command line(optparse) and loading configs(configparser)

可能的配置文件名在 get_config_files .包括PIP_CONFIG_FILE环境变量(如果已设置).

Possible file names for configurations are generated in get_config_files. Including PIP_CONFIG_FILE environment variable if it set.

parser.config RawConfigParser 的实例get_config_files中所有生成的文件名都传递给 parser.config.read

parser.config is instance of RawConfigParser so all generated file names in get_config_files are passed to parser.config.read .

尝试读取和解析文件名列表,并返回已成功解析的文件名列表.如果文件名是字符串,则将其视为单个文件名.如果无法打开以文件名命名的文件,则该文件将被忽略.这样设计的目的是,您可以指定潜在配置文件位置的列表(例如,当前目录,用户的主目录和某些系统范围的目录),并且将读取列表中的所有现有配置文件.如果不存在任何命名文件,则ConfigParser实例将包含一个空数据集.要求从文件中加载初始值的应用程序应在对任何可选文件调用read()之前,使用read_file()加载一个或多个所需文件:

Attempt to read and parse a list of filenames, returning a list of filenames which were successfully parsed. If filenames is a string, it is treated as a single filename. If a file named in filenames cannot be opened, that file will be ignored. This is designed so that you can specify a list of potential configuration file locations (for example, the current directory, the user’s home directory, and some system-wide directory), and all existing configuration files in the list will be read. If none of the named files exist, the ConfigParser instance will contain an empty dataset. An application which requires initial values to be loaded from a file should load the required file or files using read_file() before calling read() for any optional files:

这篇关于是否有可能让pip打印出正在使用的配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆