Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get pip to print the configuration it is using?

Tags:

python

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 files are in the correct place and pip is finding them.
  2. The precedence of the config settings is treated in the way one would expect from the docs
like image 498
Alexander Avatar asked Apr 12 '16 09:04

Alexander


People also ask

Which config is pip using?

On Mac OS X the configuration file is $HOME/Library/Application Support/pip/pip. conf. On Windows the configuration file is %APPDATA%\pip\pip. ini.

How does pip Conf work?

It contains configuration on how to access specific PyPI index servers when publishing a package. pip. conf on the other hand is only used by the pip tool, and pip never publishes packages, it downloads packages from them. As such, it never looks at the .

Where are pip indexes stored?

Config file locations are documented https://pip.pypa.io/en/stable/user_guide/#config-file. For me, it was located in /etc/pip.


1 Answers

For 10.0.x and higher

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

pip config list

(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

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 is function that creates parser which pip uses to read params from command line(optparse) and loading configs(configparser)

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

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

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:

like image 113
Sardorbek Imomaliev Avatar answered Oct 16 '22 07:10

Sardorbek Imomaliev