博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在Ubuntu 18.04上安装Python PIP
阅读量:2531 次
发布时间:2019-05-11

本文共 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的一些基本用法。

先决条件 (Prerequisite)

  • You can open a SSH session in your Ubuntu 18.04 system using root or a sudo enabled user.

    您可以使用root或启用sudo用户在Ubuntu 18.04系统中打开SSH会话。

Pip for Python 3 (Pip for Python 3)

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
PIP install Ubuntu 18.04

PIP3 Version

PIP3版本

适用于Python 2的Pip (Pip for Python 2)

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
Python 2 PIP install Ubuntu 18.04

PIP Version

画中画版本

基本Pip命令 (Essential Pip Commands)

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命令。

1.列出已安装的软件包 (1. List installed packages)

To find all the installed Pip packages run the following command from the terminal:

要查找所有已安装的Pip软件包,请从终端运行以下命令:

# pip3 list

2.搜索包 (2. Search package)

To search packages from the Python Package Index, execute the following pip command from the terminal:

要从Python软件包索引中搜索软件包,请在终端上执行以下pip命令:

# pip3 search keyword

3.安装软件包 (3. Install packages)

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

4.使用requirements.txt安装软件包 (4. Install packages using requirements.txt)

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

5.升级包 (5. Upgrade package)

To upgrade an installed package, use the --upgrade switch along with package name like the following command.

要升级已安装的软件包,请使用--upgrade开关以及软件包名称,如以下命令所示。

# pip3 install --upgrade package_name

6.删除包 (6. Delete package)

To remove an installed package, specify the package name to be deleted with the pip command:

要删除已安装的软件包,请使用pip命令指定要删除的软件包名称:

# pip3 uninstall package_name
If you are using Python 2 then replace pip3 with pip in the above pip commands.
如果您使用的是Python 2,请在上述pip命令中将pip3替换为pip。

摘要 (Summary)

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/

你可能感兴趣的文章
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>
两台电脑如何实现共享文件
查看>>
组合模式Composite
查看>>
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>