zoukankan      html  css  js  c++  java
  • pip安装python模块方法

    网上搜索了很多,主流的配置方法分为两种:

    摘自 1、http://www.jb51.net/article/83617.htm

    安装pip的包并确定pip安装时的镜像源地址,国内常用的地址有:

     
    http://pypi.hustunique.com 华中理工大学
     
    http://pypi.sdutlinux.org 山东理工大学
     
    http://pypi.mirrors.ustc.edu.cn 中国科学技术大学

    1> 临时指定pypi镜像源地址:

    pip install --index-url=http://pypi.jb51.net/simple/ flask
     
    2>通过配置文件永久指定pypi镜像源地址,linux下的默认配置文件一般为 ~/.pip/pip.conf
    内容配置为:
      [global]
      index-url = http://pypi.douban.com/simple #豆瓣源,可以换成其他的源
      trusted-host = pypi.douban.com            #添加豆瓣源为可信主机,要不然可能报错 
      disable-pip-version-check = true          #取消pip版本检查,排除每次都报最新的pip

    但是对我Fedora21的系统来说,如安装flask模块的话:
    pip3 install flask --find-links=http://mirrors.xxx.com.cn/pypi/simple/

    批量安装方法, 假如python需要的模块全部填写在requirement.txt中

    PyMongo>=2.7
    whoosh
    redis
    python-dateutil
    flask
    flask-login<=0.2.11
    flask-pymongo
    tornado
    passlib
    xlrd
    lxml
    six>=1.9.0
    pytz
    irc
    sleekxmpp
    Werkzeug
    Jinja2
    itsdangerous
    click

    pip3.4 install -r requirements.txt  --index-url=http://mirrors.zte.com.cn/pypi/simple/

    ---------------------------------------------------------------------------------

    备注:

    如果使用pip安装完成后发现模块依赖的版本不满足但安装成功,代码执行时报相关模块不存在问题

    (pyenv2.7) [root@localhost scripts]# python versionbuild/xxx_srpm_version_repo.py -v 5.04
    Traceback (most recent call last):
    File "versionbuild/recreate_srpm_version_repo.py", line 22, in <module>
    from libs.lib import mount_update_repo, cd, CgslError, clean_env, gen_pkg_metadata, list_httplink_files, get_file_dir,
    File "/media/B/git/SVP/CGSL/scripts/libs/lib.py", line 9, in <module>
    from fabric.api import env
    File "/usr/lib/python2.7/site-packages/fabric/__init__.py", line 3, in <module>
    from .connection import Config, Connection
    File "/usr/lib/python2.7/site-packages/fabric/connection.py", line 16, in <module>
    from paramiko.agent import AgentRequestHandler
    File "/usr/lib/python2.7/site-packages/paramiko/__init__.py", line 22, in <module>
    from paramiko.transport import SecurityOptions, Transport
    File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 91, in <module>
    from paramiko.kex_curve25519 import KexCurve25519
    File "/usr/lib/python2.7/site-packages/paramiko/kex_curve25519.py", line 6, in <module>
    from cryptography.hazmat.primitives.asymmetric.x25519 import (
    ImportError: No module named x25519

    ,这时可以采用更新模块方法

    (pyenv2.7) [root@localhost scripts]# pip install fabric --upgrade

    Requirement already up-to-date: fabric in /usr/lib/python2.7/site-packages
    Requirement already up-to-date: paramiko>=2.4 in /usr/lib/python2.7/site-packages (from fabric)
    Requirement already up-to-date: invoke<2.0,>=1.1 in /usr/lib/python2.7/site-packages (from fabric)
    Collecting cryptography>=1.1 (from fabric)
    Downloading http://mirrors.zte.com.cn/pypi/packages/e6/68/50698ce24c61db7d44d93a5043c621a0ca7839d4ef9dff913e6ab465fc92/cryptography-2.7-cp27-cp27mu-manylinux1_x86_64.whl (2.3MB)
    100% |████████████████████████████████| 2.3MB 9.9MB/s
    Requirement already up-to-date: pynacl>=1.0.1 in /usr/lib64/python2.7/site-packages (from paramiko>=2.4->fabric)
    Requirement already up-to-date: bcrypt>=3.1.3 in /usr/lib64/python2.7/site-packages (from paramiko>=2.4->fabric)
    Collecting asn1crypto>=0.21.0 (from cryptography>=1.1->fabric)
    Downloading http://mirrors.zte.com.cn/pypi/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
    100% |████████████████████████████████| 102kB 11.9MB/s
    Collecting enum34; python_version < "3" (from cryptography>=1.1->fabric)
    Downloading http://mirrors.zte.com.cn/pypi/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl
    Collecting ipaddress; python_version < "3" (from cryptography>=1.1->fabric)
    Downloading http://mirrors.zte.com.cn/pypi/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
    Collecting cffi!=1.11.3,>=1.8 (from cryptography>=1.1->fabric)
    Downloading http://mirrors.zte.com.cn/pypi/packages/8d/e9/0c8afd1579e5cf7bc0f06fbcd7cdb954cbc0baadd505973949a99337da1c/cffi-1.12.3-cp27-cp27mu-manylinux1_x86_64.whl (415kB)
    100% |████████████████████████████████| 419kB 3.4MB/s

  • 相关阅读:
    CodeForces 659F Polycarp and Hay
    CodeForces 713C Sonya and Problem Wihtout a Legend
    CodeForces 712D Memory and Scores
    CodeForces 689E Mike and Geometry Problem
    CodeForces 675D Tree Construction
    CodeForces 671A Recycling Bottles
    CodeForces 667C Reberland Linguistics
    CodeForces 672D Robin Hood
    CodeForces 675E Trains and Statistic
    CodeForces 676D Theseus and labyrinth
  • 原文地址:https://www.cnblogs.com/noxy/p/6400166.html
Copyright © 2011-2022 走看看