Home  >  Article  >  Backend Development  >  Conveniently install and manage Python libraries on Ubuntu systems using pip3

Conveniently install and manage Python libraries on Ubuntu systems using pip3

王林
王林Original
2024-01-18 10:40:06490browse

Conveniently install and manage Python libraries on Ubuntu systems using pip3

Install pip3 on Ubuntu system to easily manage Python libraries

When developing using Python, it is often necessary to introduce various third-party libraries to extend functions. In order to easily manage these libraries, we can use pip3 to install and upgrade. This article will introduce how to install and use pip3 on Ubuntu system.

Step One: Update the Software Package List
Before we begin, we should first update the system’s software package list. Open the terminal and use the following command to update:

sudo apt update

Step 2: Install pip3
Ubuntu system has Python2 and Python3 installed by default, but their package manager uses pip by default, not pip3. In order to use pip3 to manage Python libraries, we need to install pip3 first.

Run the following command in the terminal to install pip3:

sudo apt installpython3-pip

During the installation process, the system will ask whether to continue installing related dependency packages. Please type "Y" and press Enter to continue. Install.

After the installation is completed, you can use the following command to verify whether the installation is successful:

pip3 --version

If the installation is successful, the version number information of pip3 will be displayed.

Step 3: Use pip3 to install the Python library
After installing pip3, we can use it to easily install and upgrade the Python library. The following are some commonly used pip3 commands:

1. Install library
To install a Python library, just run the following command in the terminal:

pip3 install 库名

For example, to install the numpy library, Just run the following command:

pip3 install numpy

2. Upgrade the library
To upgrade the installed library, you can use the following command:

pip3 install --upgrade 库名

For example, to upgrade the numpy library, just run the following Command:

pip3 install --upgrade numpy

3. Uninstall the library
If you want to uninstall an installed library, you can use the following command:

pip3 uninstall 库名

For example, to uninstall the matplotlib library, just run the following command :

pip3 uninstall matplotlib

Step 4: Use virtual environment
In order to maintain the independence between projects, we can use virtual environments to manage the dependencies of each project.

1. Install virtual environment
To install virtual environment tools, you can use the following command:

pip3 install virtualenv

2. Create a virtual environment
In the root directory of the project, use the following command Create a new virtual environment:

virtualenv 环境名

For example, to create a virtual environment named env, just run the following command:

virtualenv env

3. Activate the virtual environment
Before creating the virtual environment After creating the environment, we need to activate it to use the Python libraries within it. Run the following command to activate the virtual environment:

source 环境名/bin/activate

For example, to activate a virtual environment named env, just run the following command:

source env/bin/activate

After activating the virtual environment, you can use the pip3 command to install it and manage project dependencies.

Step 5: Exit the virtual environment
When the project development is completed, we can use the following command to exit the virtual environment:

deactivate

Summary:
By installing and using pip3, We can easily manage Python libraries and maintain independence between projects through virtual environment tools. I hope this article will help you install pip3 and manage Python libraries on your Ubuntu system.

Reference materials:
1.https://pip.pypa.io/en/stable/quickstart/
2.https://packaging.python.org/guides/installing-using -pip-and-virtual-environments/

The above is the detailed content of Conveniently install and manage Python libraries on Ubuntu systems using pip3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn