如何在Ubuntu 18.04上安装PIP

分享于 

6分钟阅读

ubuntu

 

验证python是否已安装

要验证服务器上是否安装了Python,请运行以下命令:


root@host:~# python
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

这将检查Python版本,并确保在Ubuntu系统上安装了Python 3,通过输入Ctrl +C退出Python shell 。

安装pip

让我们从更新Ubuntu开始。

root@host:~# apt update

root@host:~# python3 --version
Python 3.7.5

接下来,我们安装PIP 。


root@host:~# apt install python3-pip
...
...
...
After this operation, 129 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...
...
...
Setting up python3.6-dev (3.6.8-1~18.04.3) ...
Setting up libpython3-dev:amd64 (3.6.7-1~18.04) ...
Setting up build-essential (12.4ubuntu1) ...
Setting up python3-dev (3.6.7-1~18.04) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
root@host:~# 

现在,检查我们安装的版本。


root@host:~# pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

用例

为了使用PIP,我们有几种选择,我们可以停留在 虚拟环境 在本例中,我们将在 虚拟虚拟虚拟虚拟 python环境(使用 venv )限制与项目依赖的交互,并避免与系统默认环境python的冲突,为了显示pip的所有可用选项,我们可以运行:


root@host:~# pip3 --help

Usage: 
 pip3 <command> [options]

Commands:
 install Install packages.
 download Download packages.
 uninstall Uninstall packages.
 freeze Output installed packages in requirements format.
 list List installed packages.
 show Show information about installed packages.
 check Verify installed packages have compatible dependencies.
 search Search PyPI for packages.
 wheel Build wheels from your requirements.
 hash Compute hashes of package archives.
 completion A helper command used for command completion.
 help Show help for commands.

General Options:
 -h, --help Show help.
 --isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
 -v, --verbose Give more output. Option is additive, and can be used up to 3 times.
 -V, --version Show version and exit.
 -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING,
 ERROR, and CRITICAL logging levels).
 --log <path> Path to a verbose appending log.
 --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
 --retries <retries> Maximum number of retries each connection should attempt (default 5 times).
 --timeout <sec> Set the socket timeout (default 15 seconds).
 --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
 --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
 --cert <path> Path to alternate CA bundle.
 --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM
 format.
 --cache-dir <dir> Store the cache data in <dir>.
 --no-cache-dir Disable the cache.
 --disable-pip-version-check
 Don't periodically check PyPI to determine whether a new version of pip is available for download.
 Implied with --no-index.

你还可以使用PIP - help获得有关"特定" PIP命令的更多信息,例如,要获取有关install命令的更多信息,请键入:

root@host:~# pip3 install --help

要搜索特定的包,可以使用:


root@host:~# pip3 search <search_string>

root@host:~# pip3 search pypi
go-pypi (0.0.4) - Go pypi
pypi-api (0) - pypi-api
upt-pypi (0.5) - PyPI frontend for upt
pypi-chat (0.0.4) - A project of pypi chat.
pypi-xmlrpc (2019.4.13) - pypi XML-RPC
Flask-Pypi-Proxy (0.5.1) - A Pypi proxy
pypi-task-demo (0.0.1) - PyPI demo
pypi-test-fiveplus (0.0.2) - PyPI Test
hello-pypi-yue (0.1.1) - The Pypi test
aeverall-testing-pypi (0.1) - Test of PyPI

要查看所有已安装的软件包,我们可以运行:

pip3 search installed package

要使用PIP安装包,我们使用:

pip3 install <package_name>

最后,要使用PIP卸载包,只需运行:

pip3 uninstall <installed_package_name>

Ubuntu  PIP  
相关文章