天天看點

python換源之pip.conf

一次性python換源可以添加-i選項:

pip install 包名 -i http://源位址

儲存為設定檔案pip.conf:

官方文檔:User Guide - pip documentation v21.1.3 (pypa.io)

https://pip.pypa.io/en/stable/user_guide/#configuration

pip允許将所有的預設選項儲存為一個ini格式的配置檔案pip.conf

---------以下來源于官方文檔------------------

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.