更新python2.7.3后安装pip,steuptools等工具

来源:互联网 发布:智慧的云计算 pdf 编辑:程序博客网 时间:2024/06/16 17:05

1.首先安装setuptools:

#yum install zlib

#yum install zlib-devel

#wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz

#tar -jxvf setuptools-1.4.2.tar.gz

#cd setuptools-1.4.2

#python setup.py install

出现报错:RuntimeError: Compression requires the (missing) zlib module,但实际已经安装成功。

解决办法:进入python27的安装目录中重新make,make install后进入setuptools-1.4.2目录中重新运行setup.py


2.接着安装pip:

#wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-6.0.7.tar.gz

#tar -jxvf pip-6.0.7.tar.gz

#cd pip-6.0.7

#python setup.py install

安装pip后,报pip:command not found 。

原因:重新编译过python,重新安装的python的bin目录不在$PATH中。这就导致了‘command not found’

解决办法,在.bashrc中加入PATH环境变量:export PATH=$HOME/bin:/usr/local/python27/bin:/usr/local/bin:$PATH

执行source命令,更新PATH。

#source .bashrc

重新pip后,报ImportError: cannot import name HTTPSHandler;

原因在于openssl,openssl-devel两个文件包未正确安装。

解决办法:用下来的命令来安装:

#yum install openssl -y

#yum install openssl-devel -y

安装完成后,重新安装python:#make #make install,最后重新安装pip。


3.安装virtualenv

virtualenv 可用来创建python中的虚拟开发环境,

#pip install vitrualenv


安装完毕后检查是否安装成功:

#virtualenv -h

正确安装结果为:
Usage: virtualenv [OPTIONS] DEST_DIROptions:  --version             show program's version number and exit  -h, --help            show this help message and exit  -v, --verbose         Increase verbosity.  -q, --quiet           Decrease verbosity.  -p PYTHON_EXE, --python=PYTHON_EXE                        The Python interpreter to use, e.g.,                        --python=python2.5 will use the python2.5 interpreter                        to create the new environment.  The default is the                        interpreter that virtualenv was installed with                        (/usr/local/python27/bin/python)  --clear               Clear out the non-root install and start from scratch.  --no-site-packages    DEPRECATED. Retained only for backward compatibility.                        Not having access to global site-packages is now the                        default behavior.  --system-site-packages                        Give the virtual environment access to the global                        site-packages.  --always-copy         Always copy files rather than symlinking.  --unzip-setuptools    Unzip Setuptools when installing it.  --relocatable         Make an EXISTING virtualenv environment relocatable.                        This fixes up scripts and makes all .pth files                        relative.  --no-setuptools       Do not install setuptools in the new virtualenv.  --no-pip              Do not install pip in the new virtualenv.  --no-wheel            Do not install wheel in the new virtualenv.  --extra-search-dir=DIR                        Directory to look for setuptools/pip distributions in.                        This option can be used multiple times.  --download            Download preinstalled packages from PyPI.  --no-download, --never-download                        Do not download preinstalled packages from PyPI.  --prompt=PROMPT       Provides an alternative prompt prefix for this                        environment.  --setuptools          DEPRECATED. Retained only for backward compatibility.                        This option has no effect.  --distribute          DEPRECATED. Retained only for backward compatibility.                        This option has no effect.