本文共 5793 字,大约阅读时间需要 19 分钟。
(Pip Install Packages) is a command line utility tool used to install and manage software packages written in Python. Like apt and yum, it is a package management system and mainly used to download and install packages from the Python Package Index (). Pip does not get installed by default in Ubuntu 18.04. However, the installation of Python Pip using the apt package manager is very simple.
(Pip安装软件包)是一个命令行实用工具,用于安装和管理以Python编写的软件包。 与apt和yum一样,它是一个程序包管理系统,主要用于从Python程序包索引( )下载和安装程序包。 在Ubuntu 18.04中默认不安装Pip。 但是,使用apt包管理器安装Python Pip非常简单。
This tutorial will show you how to install python Pip in your Ubuntu 18.04 system using apt. Thereafter, we will also check a few essential usages of Python Pip.
本教程将向您展示如何使用apt在Ubuntu 18.04系统中安装python Pip。 此后,我们还将检查Python Pip的一些基本用法。
root
or a sudo
enabled user. 您可以使用root
或启用sudo
用户在Ubuntu 18.04系统中打开SSH会话。 Ubuntu 18.04 ships with Python 3 and therefore you need to install pip3 specifically for python 3. To start with, update the package list in your system:
Ubuntu 18.04随Python 3一起提供,因此您需要专门为python 3安装pip3。首先,请更新系统中的软件包列表:
# apt update
Next, execute the following command to install Pip for python 3 and all the dependencies needed for designing Python modules.
接下来,执行以下命令以安装适用于python 3的Pip以及设计Python模块所需的所有依赖项。
# apt install python3-pip
Finally, find the version of Pip to verify the installation:
最后,找到Pip的版本以验证安装:
# pip3 --version
Although Python 3 is installed by default in Ubuntu 18.04, it is very much possible to have both Python 2 and Python 3 installed in your system. So if you want to manage packages for Python 2, you need to install pip for Python 2.
尽管在Ubuntu 18.04中默认安装了Python 3,但是很有可能在系统中同时安装了Python 2和Python 3。 因此,如果要管理适用于Python 2的软件包,则需要安装适用于Python 2的pip。
Start by updating the package list in your system.
首先更新系统中的软件包列表。
# apt update
Now install pip for Python 2 along with all other dependencies for building Python modules using following apt
command:
现在,使用以下apt
命令安装用于Python 2的pip以及用于构建Python模块的所有其他依赖项:
# apt install python-pip
Remember, the above command will install Python 2 as well if you have not installed it previously.
请记住,如果您以前未安装Python 2,则上述命令也将安装Python 2。
Finally, find the version of Pip to verify the installation:
最后,找到Pip的版本以验证安装:
# pip --version
At this point, Pip should be installed in your system. Let us walk through a few useful pip commands to get you started with it.
此时,应在系统中安装Pip。 让我们逐步讲解一些有用的pip命令,以帮助您入门。
Pip should be used within Python virtual environments which allows you to install and manage packages in a secure way for each Python projects separately. This ensures installing or deleting packages from one Python project does not affect another.
Pip应该在Python虚拟环境中使用,它可以让您以安全的方式分别为每个Python项目安装和管理软件包。 这样可以确保从一个Python项目安装或删除软件包不会影响另一个项目。
Although this tutorial will not cover about Python virtual environment or how to create it, you can use the following Pip commands either inside Python virtual environment or outside it.
尽管本教程不会介绍Python虚拟环境或其创建方法,但是您可以在Python虚拟环境内部或外部使用以下Pip命令。
To find all the installed Pip packages run the following command from the terminal:
要查找所有已安装的Pip软件包,请从终端运行以下命令:
# pip3 list
To search packages from the Python Package Index, execute the following pip command from the terminal:
要从Python软件包索引中搜索软件包,请在终端上执行以下pip命令:
# pip3 search keyword
To install the latest version of Python package using Pip, use the following command from the terminal.
要使用Pip安装最新版本的Python软件包,请在终端上使用以下命令。
# pip3 install package_name
It is also possible to install a specific version of Python package by specifying the version number with Pip command.
也可以通过使用Pip命令指定版本号来安装特定版本的Python软件包。
# pip3 install package_name==2.1
Sometimes you want to install multiple packages with the specific version number for your Python project. You can list the name of all the packages that need to be installed along with their version number in the requirements.txt file.
有时您想为您的Python项目安装具有特定版本号的多个软件包。 您可以在requirements.txt文件中列出所有需要安装的软件包的名称及其版本号。
To use requirement file for installing packages, create and edit a file by the name requirements.txt and specify a list of packages along with their version number in it.
要使用需求文件来安装软件包,请使用requirements.txt名称创建和编辑文件,并在其中指定软件包列表及其版本号。
# vi requirements.txtcertifi==2018.11.29chardet==3.0.4idna==2.8
Now to install packages, run the pip3 install
command by specifying requirements file using the -r switch:
现在要安装软件包,通过使用-r开关指定需求文件来运行pip3 install
命令:
# pip3 install -r requirements.txt
To upgrade an installed package, use the --upgrade
switch along with package name like the following command.
要升级已安装的软件包,请使用--upgrade
开关以及软件包名称,如以下命令所示。
# pip3 install --upgrade package_name
To remove an installed package, specify the package name to be deleted with the pip command:
要删除已安装的软件包,请使用pip命令指定要删除的软件包名称:
# pip3 uninstall package_name
In this tutorial, we have covered how to install Pip for Python 2 and Python 3 in an Ubuntu 18.04 system. Further, we have also covered a few basic usages of Pip to get you started with it. You can always invoke pip manual pages by using pip3 --help
from terminal to find more options and usages of python Pip.
在本教程中,我们介绍了如何在Ubuntu 18.04系统中为Python 2和Python 3安装Pip。 此外,我们还介绍了Pip的一些基本用法,以帮助您入门。 您始终可以使用终端上的pip3 --help
来调用pip手册页,以查找python Pip的更多选项和用法。
翻译自:
转载地址:http://vjlzd.baihongyu.com/