安装依赖包
[root@python ~]#yum -y install zlib zlib-devel
[root@python ~]#yum -y install openssl openssl-devel
重新编译安装Python
[root@python ~]# cd Python-2.7.10
[root@python Python-2.7.10]# ./configure --prefix=/usr/local/python2.7.10/
去掉467行的注释
[root@python Python-2.7.10]#vi Modules/Setup
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
[root@python Python-2.7.10]#make && make install
下载get-pip.py
[root@python ~]# wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
[root@python ~]# python get-pip.py
Collecting pip
Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB)
100% |████████████████████████████████| 1.1MB 404kB/s
Collecting setuptools
Downloading setuptools-18.8.1-py2.py3-none-any.whl (463kB)
100% |████████████████████████████████| 466kB 202kB/s
Collecting wheel
Downloading wheel-0.26.0-py2.py3-none-any.whl (63kB)
100% |████████████████████████████████| 65kB 138kB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-7.1.2 setuptools-18.8.1 wheel-0.26.0
[root@python ~]# pip
-bash: pip: command not found
[root@python ~]# yum -y install python-setuptools
[root@python ~]# find / -name pip
/usr/local/python2.7.10/lib/python2.7/site-packages/pip
/usr/local/python2.7.10/bin/pip
/root/.cache/pip
[root@python ~]# ln -s /usr/local/python2.7.10/bin/pip /usr/local/bin/
[root@python ~]# pip
Usage:
pip <command> [options]
Commands:
install Install 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.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output.
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don‘t periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
第三方库
MySQL的驱动:MySQL-python
要先装mysql,才能装yum install mysql mysql-devel mysql-server
[root@python ~]# pip install MySQL-python
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: MySQL-python
Running setup.py bdist_wheel for MySQL-python
Stored in directory: /root/.cache/pip/wheels/8c/0d/11/d654cad764b92636ce047897dd2b9e1b0cd76c22f813c5851a
Successfully built MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5
[root@python ~]# python
Python 2.7.10 (default, Dec 4 2015, 22:23:19)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
导入模块成功!
本文出自 “卡卡西” 博客,请务必保留此出处http://whnba.blog.51cto.com/1215711/1722862
原文:http://whnba.blog.51cto.com/1215711/1722862