python2.7.10安装步骤_python详细安装pip教程

首先安装Python

我安装了两个版本:

Python-2.7.10.tgz

Python-3.5.1.tgz

首先看一下系统自带的Python版本:

1 2 Python 2.6.6

安装Python2.7版本:

[[email protected] src]# tar zxvf Python-2.7.10.tgz

[[email protected] src]# cd Python-2.7.10

[[email protected] Python-2.7.10]# ./configure --prefix=/usr/local/python27

[[email protected] Python-2.7.10]# make && make install

把原来Python版本备份:

[[email protected] Python-2.7.10]# mv /usr/bin/python /usr/bin/python_old

建立Python2.7软连接:

1 [[email protected] Python-2.7.10]# ln -s /usr/local/python27/bin/python /usr/bin/python2 [[email protected] Python-2.7.10]# python -V3 Python 2.7.10

安装Python3.5版本:

1 [[email protected] src]# tar zxvf Python-3.5.1.tgz2 [[email protected] src]# cd Python-3.5.13 [[email protected] Python-3.5.1]# ./configure --prefix=/usr/local/python34 [[email protected] Python-3.5.1]# make && make install5 [[email protected] Python-3.5.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python36 [[email protected] Python-3.5.1]# python3 -V7 Python 3.5.1

开始安装pip

首先下载pip:

1 [[email protected] src]# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate

解压安装:

1 [[email protected] src]# tar -zxvf pip-1.5.4.tar.gz2 [[email protected] src]# cd pip-1.5.43 [[email protected] pip-1.5.4]# python setup.py install4 Traceback (most recent call last):5 File "setup.py", line 6, in

6 from setuptools import setup, find_packages7 ImportError: No module named setuptools

看到“ImportError: No module named setuptools”,缺少setuptools模块

下载安装setuptools模块:

[[email protected] src]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz#md5=f07e4b0f4c1c9368fcd980d888b29a65

[[email protected] src]# tar zxvf setuptools-12.0.3.tar.gz

[[email protected] setuptools-12.0.3]# python setup.py build

[[email protected] setuptools-12.0.3]# python setup.py install

***

z = zipfile.ZipFile(zip_filename, mode, compression=compression)

File "/usr/local/python27/lib/python2.7/zipfile.py", line 736, in __init__

"Compression requires the (missing) zlib module"

RuntimeError: Compression requires the (missing) zlib module

看到缺少zlib模块,解决方法:

[[email protected] setuptools-12.0.3]# yum install zlib zlib-devel

安装完成之后需要重新编译Python2.7和3.5:

[[email protected] setuptools-12.0.3]# cd ../Python-2.7.10

[[email protected] Python-2.7.10]# ./configure --prefix=/usr/local/python27/

[[email protected] Python-2.7.10]# make && make install

[[email protected] Python-2.7.10]# rm -rf /usr/bin/python

[[email protected] Python-2.7.10]# rm -rf /usr/bin/python3

[[email protected] Python-2.7.10]# ln -s /usr/local/python27/bin/python /usr/bin/python

[[email protected] Python-2.7.10]# cd ../setuptools-12.0.3

[[email protected] setuptools-12.0.3]# python setup.py build

running build

running build_py

[[email protected] setuptools-12.0.3]# python setup.py install

***

Processing dependencies for setuptools==12.0.3

Finished processing dependencies for setuptools==12.0.3

重新安装之后成功了!但是现在只是把setuptools安装好了,在重新安装pip:

[[email protected] pip-1.5.4]# python setup.py install

Installed /usr/local/python27/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg

Processing dependencies for pip==1.5.4

Finished processing dependencies for pip==1.5.4

[[email protected] pip-1.5.4]# python -m pip install a

/usr/bin/python: cannot import name HTTPSHandler; ‘pip‘ is a package and cannot be directly executed

根据上面提示又是缺少HTTPSHandler模块,安装:

[[email protected] ~]# yum install openssl openssl-devel -y

然后再重新安装编译Python,安装完成时候在重新安装pip:

[[email protected] ~]# python

Python 2.7.10 (default, Apr 29 2016, 11:43:29)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import virtualenv

Traceback (most recent call last):

File "", line 1, in ImportError: No module named virtualenv

>>> exit()

[[email protected] ~]# python -m pip install virtualenv

Downloading/unpacking virtualenv

Downloading virtualenv-15.0.1-py2.py3-none-any.whl (1.8MB): 1.8MB downloaded

Installing collected packages: virtualenv

Successfully installed virtualenv

Cleaning up...

[[email protected] ~]# python

Python 2.7.10 (default, Apr 29 2016, 11:43:29)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import virtualenv

>>>

~ok,已经成功了!

如果安装的时候不出问题是最好的,所以在安装软件的时候一点要先把依赖包安装好!

原文:http://www.cnblogs.com/allan-king/p/5445879.html

你可能感兴趣的:(python2.7.10安装步骤_python详细安装pip教程)