Python pip Installation and Usage
Category Programming Technology
pip is the Python package management tool that provides functionalities for searching, downloading, installing, and uninstalling Python packages.
Currently, if you download the latest version of the installer from python.org, it comes with the pip tool.
>
Note: pip is included with Python 2.7.9+ or Python 3.4+.
pip Official Website: https://pypi.org/project/pip/
You can check if it is already installed with the following commands:
pip --version # Command for Python 2.x
pip3 --version # Command for Python 3.x
If you haven't installed it yet, you can install it using the following methods:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # Download the installation script
$ sudo python get-pip.py # Run the installation script
>
Note: The version of Python used to run the installation script will associate pip with that version. For Python3, execute the following command:
$ sudo python3 get-pip.py # Run the installation script.
Typically, pip corresponds to Python 2.7, and pip3 corresponds to Python 3.x.
Some Linux distributions can install pip directly using their package manager, such as Debian and Ubuntu:
sudo apt-get install python-pip
Most Common pip Commands
Display version and path
pip --version
Get help
pip --help
Upgrade pip
pip install -U pip
>
If this upgrade command encounters issues, you can use the following command:
sudo easy_install --upgrade pip
Install package
pip install SomePackage # Latest version
pip install SomePackage==1.0.4 # Specific version
pip install 'SomePackage>=1.0.4' # Minimum version
For example, to install Django, use the following command:
pip install Django==1.7
Upgrade package
pip install --upgrade SomePackage
To upgrade a specific package, use ==, >=, <=, >, < to specify a version number.
Uninstall package
pip uninstall SomePackage
Search package
pip search SomePackage
Display installed package information
pip show
View detailed information of a specific package
pip show -f SomePackage
List installed packages
pip list
View upgradable packages
pip list -o
Upgrading pip
Linux or macOS
pip install --upgrade pip # Python 2.x
pip3 install --upgrade pip # Python 3.x
Windows platform upgrade:
python -m pip install -U pip # Python 2.x
python -m pip3 install -U pip # Python 3.x
Tsinghua Open Source Software Mirror for pip
Using a domestic mirror can be much faster:
Temporary use:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
For example, to install Django:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Django
To set this as the default, upgrade pip to the latest version (>=10.0.0) and configure:
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
If the network connection to the default pip source is poor, use this mirror to upgrade pip temporarily:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
Important Notes
If both Python2 and Python3 have pip, use them as follows:
Python2:
python2 -m pip install XXX
Python3:
python3 -m pip install XXX
#
-
** nameless_zhang
* nam**[email protected]
If you encounter a "connection timeout" due to some local network issues when using pip, you can use domestic mirror sites to download:
Douban: https://pypi.doubanio.com/simple/
Tsinghua: https://pypi.tuna.tsinghua.edu.cn/simple
Commands are as follows:
pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com packagename # packagename is the name of the package to download
pip install -i http://e.pypi.python.org --trusted-host e.pypi.python.org --upgrade pip # Upgrade pip
** nameless_zhang
* nam**[email protected]
** Click to Share Notes
-
-
-