python第三库安装方法记录

发布时间:2019-09-17 07:45:14编辑:auto阅读(2075)

    一、Python包管理工具  
    Python包管理工具,可以很方便的安装第三方模块

    1. setuptools

    下载地址:https://pypi.python.org/pypi/setuptools/    
    setuptools-24.0.3.tar.gz的下载地址:    
    https://pypi.python.org/packages/84/24/610d8bb87219ed6d0928018b7b35ac6f6f6ef27a71ed6a2d0cfb68200f65/setuptools-24.0.3.tar.gz

    1)Ubuntu 安装:sudo apt-get install python-setuptools    
    2)CentOS 安装:    

    tar zxvf setuptools-24.0.3.tar.gz    
    cd setuptools-24.0.3    
    python setup.py build    
    python setup.py install

    3)windows安装:先下载ez_setup.py,命令行进入其目录,执行  
    python setup.py build 
    python setup.py install

    目前还未了解其用法,mysqldb对其有依赖关系。


    2. pip(建议使用pip管理插件包)

    下载地址:https://pypi.python.org/pypi/pip/  下载pip-8.1.2.tar.gz    
    1)Ubuntu 安装:sudo apt-get install python-pip    
    2)windows安装:下载工具包,命令行进入其目录,

    注:windows python2.7自带版本较低,初次使用时会提示升级。  
    D:\Python27\Scripts>pip install --upgrade pip    
    You are using pip version 7.0.1, however version 8.1.2 is available.    
    You should consider upgrading via the 'pip install --upgrade pip' command.    
    Collecting pip    
      Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)    
        100% |████████████████████████████████| 1.2MB 48kB/s    
    Installing collected packages: pip    
      Found existing installation: pip 7.0.1    
        Uninstalling pip-7.0.1:    
          Successfully uninstalled pip-7.0.1    
      Failed to write executable - trying to use .deleteme logic    
    Successfully installed pip-8.1.2

    D:\Python27\Scripts>

    3)CentOS6.x 下安装  
    tar zxvf pip-8.1.2.tar.gz    
    cd pip-8.1.2    
    python setup.py build    
    python setup.py install

    使用示例:

    # 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.    
      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.

    例如:安装redis包

    # pip install redis  
    # pip list

    MySQL-python (1.2.3)  
    pip (8.1.2)    
    redis (2.10.5)    
    setuptools (24.0.3)


    二、常用第三方Python插件安装

    1. MySQLdb的安装与使用 
     
    (1) windows版本MySQLdb安装    
    http://www.codegood.com/downloads    
    下载MySQL-python-1.2.3.win-amd64-py2.7.ext直接安装即可。    
    python测试模块安装后测试。    
    import MySQLdb

    (2) CentOS6.x下安装安装MySQLdb模块

    注:安装MySQLdb模块过程中会提示需要安装setuptools,所以需要先安装setuptools

    [root@ MySQL-python-1.2.3]# python setup.py build 
    Traceback (most recent call last):    
      File "setup.py", line 5, in <module>    
        from setuptools import setup, Extension    
    ImportError: No module named setuptools

    MySQL-python-1.2.3.tar.gz的下载地址:  
    http://jaist.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz    
    或这里下载:    
    http://sourceforge.net/projects/mysql-python/    
    https://pypi.python.org/pypi/MySQL-python/1.2.4

    setuptools-24.0.3.tar.gz的下载地址:  
    https://pypi.python.org/packages/84/24/610d8bb87219ed6d0928018b7b35ac6f6f6ef27a71ed6a2d0cfb68200f65/setuptools-24.0.3.tar.gz

    安装过程如下:  
    tar xvf MySQL-python-1.2.3.tar.gz    
    cd MySQL-python-1.2.3    
    python setup.py build    
    python setup.py install


    (3) pip方式安装

    用 pip 安装 MySQLdb 也就是一句命令,需要事先安装pip。  
    pip install MySQL-python


    2. 安装 paramiko模块

    1) linux下安装paramiko

    paramiko是一个用于做远程控制的模块,使用该模块可以对远程服务器进行命令或文件操作。  
    pycrypto,由于 paramiko 模块内部依赖pycrypto,所以先下载安装pycrypto

    # 下载安装 pycrypto

    wget http://files.cnblogs.com/files/wupeiqi/pycrypto-2.6.1.tar.gz    
    tar -xvf pycrypto-2.6.1.tar.gz    
    cd pycrypto-2.6.1    
    python setup.py build    
    python setup.py install

    # 进入python环境,导入Crypto检查是否安装成功

    # 下载安装 paramiko

    wget http://files.cnblogs.com/files/wupeiqi/paramiko-1.10.1.tar.gz    
    tar -xvf paramiko-1.10.1.tar.gz    
    cd paramiko-1.10.1    
    python setup.py build    
    python setup.py install

    # 进入python环境,导入paramiko检查是否安装成功

    2) windows下安装paramiko

    D:\Python27\Scripts>pip install paramiko
    Collecting paramiko
      Downloading paramiko-2.0.1-py2.py3-none-any.whl (171kB)
        100% |████████████████████████████████| 174kB 12kB/s
    Collecting cryptography>=1.1 (from paramiko)
      Downloading cryptography-1.4-cp27-cp27m-win_amd64.whl (1.3MB)
        100% |████████████████████████████████| 1.3MB 54kB/s
    Collecting pyasn1>=0.1.7 (from paramiko)
      Downloading pyasn1-0.1.9-py2.py3-none-any.whl
    Collecting cffi>=1.4.1 (from cryptography>=1.1->paramiko)
      Downloading cffi-1.7.0-cp27-cp27m-win_amd64.whl (153kB)
        100% |████████████████████████████████| 153kB 17kB/s
    Collecting idna>=2.0 (from cryptography>=1.1->paramiko)
      Downloading idna-2.1-py2.py3-none-any.whl (54kB)
        100% |████████████████████████████████| 61kB 10kB/s
    Collecting enum34 (from cryptography>=1.1->paramiko)
      Downloading enum34-1.1.6-py2-none-any.whl
    Collecting six>=1.4.1 (from cryptography>=1.1->paramiko)
      Downloading six-1.10.0-py2.py3-none-any.whl
    Collecting ipaddress (from cryptography>=1.1->paramiko)
      Downloading ipaddress-1.0.16-py27-none-any.whl
    Requirement already satisfied (use --upgrade to upgrade): setuptools>=11.3 in d:\python27\lib\site-packages\setuptools-2
    4.0.3-py2.7.egg (from cryptography>=1.1->paramiko)
    Collecting pycparser (from cffi>=1.4.1->cryptography>=1.1->paramiko)
      Downloading pycparser-2.14.tar.gz (223kB)
        100% |████████████████████████████████| 225kB 13kB/s
    Installing collected packages: pycparser, cffi, idna, enum34, pyasn1, six, ipaddress, cryptography, paramiko
      Running setup.py install for pycparser ... done
    Successfully installed cffi-1.7.0 cryptography-1.4 enum34-1.1.6 idna-2.1 ipaddress-1.0.16 paramiko-2.0.1 pyasn1-0.1.9 py
    cparser-2.14 six-1.10.0

    D:\Python27\Scripts>

    3. linux下安装连接cx_oracle库,用于python连接oracle数据库

    博客链接:

    http://koumm.blog.51cto.com/703525/1436501

    ...

关键字