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
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
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 decorator==4.0.11 ipython==6.1.0 ipython-genutils==0.2.0 pexpect==4.2.1 ptyprocess==0.5.2 Pygments==2.2.0 six==1.10.0 traitlets==4.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: ipython-dev@scipy.org 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 <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-i
ndex.
來源:http://www.cnblogs.com/chengd/p/7078588.html