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

Conveniently install and manage Python libraries on Ubuntu systems using pip3

王林
Release: 2024-01-18 10:40:06
Original
551 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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 库名
Copy after login

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

pip3 install numpy
Copy after login

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

pip3 install --upgrade 库名
Copy after login

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

pip3 install --upgrade numpy
Copy after login

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

pip3 uninstall 库名
Copy after login

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

pip3 uninstall matplotlib
Copy after login

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
Copy after login

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

virtualenv 环境名
Copy after login

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

virtualenv env
Copy after login

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
Copy after login

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

source env/bin/activate
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template