What is pip's full name? I don't find any definition online, but this "The PyPA recommended tool for installing and managing Python packages." from pip website.(PyPA: Python Parser) So pip is just a command line tool to manage python packages, which is to say, it is not a python command! And you can't run it directly from python!
On windows, to use pip, you need to add the path: Python2/Scripts (pip.exe resides in it).
# Upgrade pip itself. It also works in windows cmd. pip install -U pip # Windows version python -m pip install -U pip pip install SomePackage==1.0.4 # specific version pip install 'SomePackage>=1.0.4' # minimum version pip uninstall somePackage pip list pip list --outdated pip show somePackege pip search "query" # -d, --download pip install -d /somePath package # Install offline. # --no-index: Ignore package index (only looking at --find-links URLs instead). # -f, --find-links url: If a url or path to an html file, then parse for links to archives. If a local path or file:// url that's a directory,then look for archives in the directory listing. pip install --no-index -f /somePath package pip install ./downloads/SomeProject-1.0.4.tar.gz # Or install from the requirement # -r, --requirement pip install -d /somePath -r requirementFile
pip freeze # docutils==0.11 # Jinja2==2.7.2 # MarkupSafe==0.19 # Pygments==1.6 # Sphinx==1.2.2 # Generate a requirements file: pip freeze > requirements.txt # Install from it: pip install -r requirements.txt
- On Unix the default configuration file is: $HOME/.config/pip/pip.conf which respects the XDG_CONFIG_HOME environment variable.
- 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.
- Legacy per-user configuration files
- On Unix and Mac OS X 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 Mac OS X the file is $VIRTUAL_ENV/pip.conf
- On Windows the file is: %VIRTUAL_ENV%\pip.ini
- 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 Mac OS X 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
- Site-wide configuration is not supported on Windows Vista
If multiple configuration files are found by pip then they are combined in the following order:
- Firstly the site-wide file is read, then
- The per-user file is read, and finally
- 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 is the one that 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 = http://download.zope.org/ppix
Decreasing the timeout to 10 seconds when running the freeze (Freezing Requirements) 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 and --no-cache-dir, falsy values have to be used:
[global] no-cache-dir = false [install] no-compile = no
Appending options like --find-links can be written on multiple lines:
[global] find-links = http://download.example.com [install] find-links = http://mirror1.example.com http://mirror2.example.com
Change pypi host
pip install -i http://mirrorURL/simple packageName --trust-host mirrorURL pip install -i http://pypi.douban.com/simple django --trusted-host pypi.douban.com
pypi.python.org pypi.douban.com pypi.hustunique.com
To permanently add the customized pypi host, add in ~/.config/pip/pip.conf:
[global] timeout = 10 index-url = http://pypi.douban.com/simple trusted-host = pypi.douban.com
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:
export PIP_DEFAULT_TIMEOUT=60 ## This is the same as passing the option to pip directly: pip --default-timeout=60 [...]
To set options that can be set multiple times on the command line, just add spaces in between values. For example:
export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com" # Is the same as calling: pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com
Precedence from high to low:
- Command line options
- Environment variables
- The config file. Within the config file, command specific sections have precedence over the [global] section.
--host=foo overrides PIP_HOST=foo PIP_HOST=foo overrides a config file with [global] host = foo