转载 本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-02/157062.htm
pip类似RedHat里面的yum,安装Python包非常方便。本节详细介绍pip的安装、以及使用方法。
1、下载pip安装包
[root@localhost ~]# wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
https://pypi.org/project/pip/#files
2、解压pip安装包
[root@localhost ~]# tar xf pip-9.0.1.tar.gz
3、安装pip
[root@localhost ~]# cd pip-9.0.1
[root@localhost pip-9.0.1]# python3 setup.py install
安装后,可执行文件在 /usr/local/python3/bin 做一个软连就可以了 ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3.7
4、pip使用详解
pip安装模块报错,提示没有ssl模块
[root@localhost ipython-6.1.0]# pip install traitlets
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting traitlets
Could not fetch URL https://pypi.python.org/simple/traitlets/: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement traitlets (from versions: )
No matching distribution found for traitlets
#没有安装openssl-devel,然后重新编译安装python3.6
[root@localhost pip-9.0.1]# yum install openssl-devel -y
#进入python3.6解压包目录
[root@localhost Python-3.6.1]#make clean
[root@localhost Python-3.6.1]# ./configure
[root@localhost Python-3.6.1]# make && make install
安装openssl-devel并重新编译安装python3后,再次测试pip安装模块
[root@localhost ~]# pip install ‘traitlets’
Collecting traitlets
Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
100% |?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..?..| 81kB 87kB/s
Collecting six (from traitlets)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting ipython-genutils (from traitlets)
Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting decorator (from traitlets)
Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: six, ipython-genutils, decorator, traitlets
Successfully installed decorator-4.0.11 ipython-genutils-0.2.0 six-1.10.0 traitlets-4.3.2
#安装成功
pip uninstall Package:卸载模块
[root@localhost pip-9.0.1]# pip uninstall traitlets
Uninstalling traitlets-4.3.2:
…
packages/traitlets/utils/tests/test_importstring.py
Proceed (y/n)? y
Successfully uninstalled traitlets-4.3.2
pip freeze:按需求格式输出已安装的模块
[root@localhost pip-9.0.1]# pip freeze
decorator4.0.11
ipython6.1.0
ipython-genutils0.2.0
pexpect4.2.1
ptyprocess0.5.2
Pygments2.2.0
six1.10.0
traitlets4.3.2
pip list --format=(legacy|columns):安装指定格式输出已安装的模块;和pip freeze类似
[root@localhost pip-9.0.1]# pip list --format=legacy
decorator (4.0.11)
ipython (6.1.0)
ipython-genutils (0.2.0)
pexpect (4.2.1)
pip (9.0.1)
ptyprocess (0.5.2)
Pygments (2.2.0)
setuptools (28.8.0)
six (1.10.0)
traitlets (4.3.2)
[root@localhost pip-9.0.1]# pip list --format=columns
Package Version
decorator 4.0.11
ipython 6.1.0
ipython-genutils 0.2.0
pexpect 4.2.1
pip 9.0.1
ptyprocess 0.5.2
Pygments 2.2.0
setuptools 28.8.0
six 1.10.0
traitlets 4.3.2
pip show Package:显示已安装的模块信息
[root@localhost pip-9.0.1]# pip show traitlets
Name: traitlets
Version: 4.3.2
Summary: Traitlets Python config system
Home-page: http://ipython.org
Author: IPython Development Team
Author-email: [email protected]
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires: ipython-genutils, six, decorator
pip -h:余下的选项可以通过-h查看,这里不做过多介绍
[root@localhost pip-9.0.1]# pip -h
Usage:
pip [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 to a verbose appending log.
–proxy Specify a proxy in the form [user:passwd@]proxy.server:port.
–retries Maximum number of retries each connection should attempt (default 5 times).
–timeout Set the socket timeout (default 15 seconds).
–exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
–trusted-host Mark this host as trusted, even though it does not have valid or any HTTPS.
–cert Path to alternate CA bundle.
–client-cert Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
–cache-dir
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-02/157062.htm