In this tutorial, we’ll go over the steps to install pip in Linux. The pip command allows us to install Python packages from the Python Package Index or PyPI.
The pip command can be installed with the package manager for your Linux distribution. In this tutorial, we’ll work with Ubuntu’s apt package manager to install pip.
The pip command stands for Package Installer for Python. Similar to the apt command for Debian-based distributions, yum and rpm commands for Red Hat-based distributions, and pacman for Arch-based distributions, pip command helps install packages for Python.
When you’re working with Python, you can install the available packages using the system’s default package manager or work with pip to install Python-specific packages directly from their official index.
With the default package manager, there will always be packages that just aren’t available. But with pip, you can rest assured that most of the packages that you’ll require (and many more) will be available right there.
如何在Linux中安装Pip? (How To Install Pip In Linux)
So how do we go about installing pip in Linux It’s really simple. Let’s walk through the simple steps to get pip up and running on our Ubuntu server here.
Depending on which version of Python you’re working with, you can install pip or pip3 and make sure that you have the right packages being installed.
根据您使用的Python版本,可以安装pip或pip3并确保已安装正确的软件包。
如何在Linux中使用PIP命令? (How to Use PIP Command in Linux)
Now coming to the usage of PIP, we’ll learn how to
现在开始使用PIP,我们将学习如何
install
安装
uninstall
卸载
search
搜索
list existing packages
列出现有软件包
show details of a package
显示包裹的细节
I’ve installed python3-pip on Ubuntu since I mostly work with Python 3.x. You can replace the pip3 part in the below examples with pip if you’re working with pip for Python 2.x.
We’ll install the numpy library as an example here.
我们将在此处安装numpy库作为示例。
root@ubuntu:~# pip3 install For Example -- root@ubuntu:~# pip3 install numpy
Pip Install Example
点安装示例
If you would like to know what packages are available, you can use the search functionality of the pip command.
如果您想知道可用的软件包,可以使用pip命令的搜索功能。
root@ubuntu:~# pip3 search numpy
Pip Search Example
点搜索示例
How to find the list of installed Python packages We’ll use the list option for the pip command.
如何找到已安装的Python软件包列表? 我们将对pip命令使用list选项。
root@ubuntu:~# pip3 list
Pip List Example
点列表示例
You can safely ignore the warning in the output because it’s just to let us know that the default output format will change in the future.
您可以放心地忽略输出中的警告,因为这只是为了告诉我们默认输出格式将来会更改。
If you’d like to know more about a package that you’ve installed, just use the show command.
如果您想了解有关已安装软件包的更多信息,请使用show命令。
root@ubuntu:~# pip3 uninstall numpy
Pip Show Example
点显示示例
And to uninstall a package, we simply use pip3 uninstall as below.
要卸载软件包,我们只需使用pip3卸载 ,如下所示。
root@ubuntu:~# pip3 uninstall numpy
Pip Uninstall Example
点卸载示例
结论 (Conclusion)
I know, it was really easy to install pip in Linux so I took the liberty to explain how you can start with using the command right away. As you work with Python, you’ll find yourself working with the pip command very often for installing and uninstalling packages.