pip installation guide under Python3

王林
Release: 2024-01-18 10:02:06
Original
1421 people have browsed it

pip installation guide under Python3

In Python3, pip is the Python package manager, which can help developers manage the installation, upgrade, and uninstallation of Python packages. However, sometimes when installing Python3, pip is not automatically installed. This article will provide you with a complete guide to installing pip in Python 3 to help Python developers who want to use pip get started more quickly.

1. Install pip on Linux or macOS

For Linux or macOS users, we can use the following command to install pip:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ sudo python3 get-pip.py
Copy after login

First, we need to install pip from the URL: https://bootstrap.pypa.io/get-pip.py Download get-pip.py, and then run the file using Python3. If the version of Linux or macOS you are using does not support curl, you can use wget to obtain the get-pip.py file:

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
Copy after login

2. Install pip on Windows

For Windows systems, we The following steps are required to install pip:

  1. Confirm that you have installed Python3 correctly.
  2. Download the get-pip.py file. Open the https://bootstrap.pypa.io/get-pip.py link in your browser and select "Save As" to download the file to your computer.
  3. Open a command prompt (PowerShell on Windows 10) and use the cd command to change to the directory containing the get-pip.py file.
  4. Run the following command to install pip:
C:Python3python.exe get-pip.py
Copy after login
Copy after login

Please replace "C:Python3python.exe" with your Python3 installation directory. For example, if you installed Python3 in the C:Python3 directory, you should run the following command:

C:Python3python.exe get-pip.py
Copy after login
Copy after login

3. Use of pip

If you have successfully installed pip, then next During development, you can use it to install, upgrade, and uninstall Python packages. The following are some common commands for pip:

  1. Install a package:
$ pip3 install 包名
Copy after login

For example:

$ pip3 install requests
Copy after login
  1. Upgrade a package:
$ pip3 install --upgrade 包名
Copy after login

For example:

$ pip3 install --upgrade requests
Copy after login
  1. Uninstall a package:
$ pip3 uninstall 包名
Copy after login

For example:

$ pip3 uninstall requests
Copy after login
  1. View installed packages :
$ pip3 freeze
Copy after login

The above command can list all installed Python packages and their version numbers. If you wish to save its output to a file, you can use the following command:

$ pip3 freeze > requirements.txt
Copy after login
  1. Install the required packages according to the requirements.txt file:

Assuming you already have A requirements.txt file, which contains all Python packages and version numbers, you can install these packages through the following commands:

$ pip3 install -r requirements.txt
Copy after login

These commands will bring great convenience when you develop Python3 .

Summary

In this article, we introduce you to a complete guide to installing pip in Python3, and provide some command examples to help use pip. Using pip can make the installation and upgrade of Python packages more convenient, ensuring that developers have the latest tools and libraries for development. I hope that readers can enter the world of Python3 development more easily through the introduction of this article.

The above is the detailed content of pip installation guide under Python3. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!