在Python中,有许多好用的小工具,今天简单介绍一下pip的使用方法,后续有其他的会记录进行补充;
pip官网:https://pypi.org/project/pip/
PyPI使用国内源
通过几次 pip 的使用,对于默认的 pip 源的速度实在无法忍受,于是便搜集了一些国内的pip源,如下:
阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
[root@VM_2_13_centos piptest]# pip install flask Looking in indexes: http://pypi.douban.com/simple Collecting flask The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'. Could not find a version that satisfies the requirement flask (from versions: ) No matching distribution found for flask
解决方法:(~/.pip/pip.conf)
[root@VM_2_13_centos .pip]# vim pip.conf [global] index-url = http://pypi.douban.com/simple [install] trusted-host=pypi.douban.com
重新安装,安装成功
[root@VM_2_13_centos .pip]# pip install flask Looking in indexes: http://pypi.douban.com/simple Collecting flask Downloading http://pypi.doubanio.com/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB) 100% |████████████████████████████████| 92kB 7.3MB/s Requirement already satisfied: Werkzeug>=0.14 in /usr/lib/python2.7/site-packages (from flask) (0.14.1) Requirement already satisfied: click>=5.1 in /usr/lib64/python2.7/site-packages (from flask) (7.0) Requirement already satisfied: itsdangerous>=0.24 in /usr/lib/python2.7/site-packages (from flask) (1.1.0) Requirement already satisfied: Jinja2>=2.10 in /usr/lib/python2.7/site-packages (from flask) (2.10) Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib64/python2.7/site-packages (from Jinja2>=2.10->flask) (1.1.0) Installing collected packages: flask Successfully installed flask-1.0.2
导出系统所在安装的安装列表到requiremwnts.txt文件中
[root@VM_2_13_centos piptest]# pip freeze > requirements.txt [root@VM_2_13_centos piptest]# cat requirements.txt Babel==0.9.6 backports.ssl-match-hostname==3.4.0.2 blivet==0.61.15.65 cffi==1.6.0 chardet==2.2.1 Cheetah==2.4.4 Click==7.0 cloud-init==0.7.9 configobj==4.7.2 coverage==3.6b3 cryptography==1.7.2 cupshelpers==1.0 decorator==3.4.0 di==0.3 enum34==1.0.4 ethtool==0.8 firstboot==19.5 Flask==1.0.2 fros==1.0 idna==2.4 iniparse==0.4 initial-setup==0.3.9.40 ipaddress==1.0.16 IPy==0.75 itsdangerous==1.1.0 Jinja2==2.10 jsonpatch==1.2 jsonpointer==1.9 jsonschema==2.5.1 jwcrypto==0.2.1 kitchen==1.1.1 langtable==0.0.31 Markdown==2.4.1 MarkupSafe==1.1.0 MySQL-python==1.2.5 ntplib==0.3.2 oauthlib==2.0.1 perf==0.1 Pillow==2.0.0 ply==3.4 policycoreutils-default-encoding==0.1 prettytable==0.7.2 pyasn1==0.1.9 pycparser==2.14 pycups==1.9.63 pycurl==7.19.0 Pygments==1.4 pygobject==3.22.0 pygpgme==0.3 pyinotify==0.9.4 pykickstart==1.99.66.12 pyliblzma==0.5.3 pymongo==3.7.1 pyparted==3.9 python-augeas==0.5.0 python-dmidecode==3.12.2 python-linux-procfs==0.4.9 python-meh==0.25.2 python-nss==0.16.0 pytz==2016.10 pyudev==0.15 pyxattr==0.5.1 PyYAML==3.10 redis==2.10.6 repoze.lru==0.4 requests==2.6.0 scdate==1.10.6 schedutils==0.4 seobject==0.1 sepolicy==1.1 setroubleshoot==1.1 six==1.9.0 slip==0.4.0 slip.dbus==0.4.0 tencentcloud-sdk-python==3.0.26 urlgrabber==3.10 urllib3==1.10.2 Werkzeug==0.14.1 yum-langpacks==0.4.2 yum-metadata-parser==1.1.4
从requiremwnts.txt文件进行安装
[root@VM_2_13_centos piptest]# pip install -r requirements.txt