Home >Backend Development >Python Tutorial >Starting from scratch: Mastering installing Python libraries using pip
Start from scratch: Learn to use pip to install Python packages, you need specific code examples
Introduction: Python is a popular programming language with rich Third-party libraries and packages. In order to better develop and use Python, it is an important step to learn to use pip to install Python packages. This article will start from scratch, detail how to use pip to install Python packages, and provide specific code examples.
1. What is pip?
pip is a package management tool for Python, which can easily help us install, upgrade and uninstall Python packages. pip is easy to use, powerful, and supports automatic resolution of dependencies. It is an indispensable tool for Python developers.
2. Install pip
Before starting to use pip, we first need to make sure that we have installed Python correctly. pip is usually installed with Python, but manual installation may be required in some cases.
python get-pip.py
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then, we execute the following command to install pip:
python get-pip.py
3. Use pip to install the Python package
Once We successfully installed pip and can start using it to install Python packages. The following are some commonly used pip command examples:
pip install package_name
For example, we want to To install the numpy package, you can execute the following command:
pip install numpy
pip install package_name==version
For example, if we want to install version 1.18.1 of numpy, we can execute the following command:
pip install numpy==1.18.1
pip install --upgrade package_name
For example, we can execute the following command to upgrade the numpy package:
pip install --upgrade numpy
pip uninstall package_name
For example, if we want to uninstall the numpy package, we can execute the following command:
pip uninstall numpy
4. Resolve dependencies
pip has the function of automatically resolving dependencies. This means that when we install a package, pip will automatically install other packages that the package depends on. This can greatly simplify our work.
5. Common options of pip
Pip also has some common options that can help us use it better. The following are some examples of commonly used options:
pip list
pip search package_name
For example, if we want to find packages related to matplotlib, we can execute the following Command:
pip search matplotlib
pip install package_name --index-url=URL
where the URL is the installation source we want to use . For example, we can use Tsinghua University's pip image to install the numpy package and execute the following command:
pip install numpy --index-url=https://pypi.tuna.tsinghua.edu.cn/simple
6. Summary
This article starts from scratch, details how to use pip to install Python packages, and provides specific code examples. pip is an indispensable tool for Python developers. It is convenient, powerful, and supports automatic resolution of dependencies. By learning to use pip, we can better develop and use Python and improve our programming efficiency. I hope this article can help beginners better master the basic skills of using pip.
The above is the detailed content of Starting from scratch: Mastering installing Python libraries using pip. For more information, please follow other related articles on the PHP Chinese website!