centos6.5安装python2.7
下载安装包解压安装修改默认pythonyum python26修复pip安装安装setuptools安装pip安装pymysqlmysql模块安装下载安装包mkdir -p /usr/local/pythoncd /usr/local/pythonhttps://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz解压[ro
下载安装包
mkdir -p /usr/local/python
cd /usr/local/python
https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
解压
[root@dev22 python]# tar xvf Python-2.7.14.tgz
[root@dev22 python]# cd Python-2.7.14
安装
# 安装zlib
[root@dev22 Python-2.7.14]# yum install zlib zlib-devel
# 安装gcc
[root@dev22 Python-2.7.14]# yum install gcc-c++
# 安装openssl
[root@dev22 Python-2.7.14]# yum install openssl openssl-devel -y
[root@dev22 Python-2.7.14]# ./configure --prefix=/usr/local/python/Python-2.7.14 --with-zlib --enable-shared -enable-unicode=ucs4
[root@dev22 Python-2.7.14]# make
[root@dev22 Python-2.7.14]# make install
configure是源码安装的第一步,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足安装软件的依赖关系。
关于configure的介绍:http://blog.csdn.net/luckywang1103/article/details/18674231
关于-enable-shared的介绍:http://blog.csdn.net/z1988316/article/details/7894734
-enable-unicode=ucs4:为了解决RHL6.6编码采用ucs4编码的问题,RHL5.5不需要
修改默认python
#安装完成后,发现默认python还是2.6.6
[root@dev22 Python-2.7.14]# python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
[root@dev22 Python-2.7.14]# which python
/usr/bin/python
[root@dev22 Python-2.7.14]# cd /usr/bin
#删除自带的python
[root@dev22 bin]# rm -rf python
#创建软连接将python解释器指向新安装的地址
[root@dev22 bin]# ln -s /usr/local/python/Python-2.7.14/bin/python python
#再执行python发现确认lib库
[root@dev22 bin]# python
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
## 解决方法1:
[root@dev22 bin]# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/python/Python-2.7.14/lib
# 可以找到libpython2.7.so.1.0 -> libpython2.7.so.1.0
[root@dev22 bin]# /sbin/ldconfig -v
......
/usr/local/python/Python-2.7.14/lib:
libpython2.7.so.1.0 -> libpython2.7.so.1.0
......
#再次执行python已经变成2.7的版本
[root@dev22 bin]# python
Python 2.7.14 (default, Nov 17 2017, 09:40:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
## 解决方法2:
cd /etc/ld.so.conf.d/
echo "/usr/local/python/Python-2.7.14/lib" > python2.7.conf
ldconfig
yum python2.6修复
由于yum使用了原来python2.6的一些脚本,需要将yum重新导向原来的python2.6解释器才可以使用
[root@dev22 bin]# which yum
/usr/bin/yum
#修改yum使用的python版本
[root@dev22 bin]# vim /usr/bin/yum
#!/usr/bin/python2.6
pip安装
安装setuptools
下载地址:
https://pypi.python.org/pypi/setuptools#downloads
https://pypi.python.org/packages/7c/cb/bdfbb0b6a56459d5461768de824d4f40ec4c4c778f3a8fb0b84c25f03b68/setuptools-37.0.0.zip#md5=f905ca70d2db37b7284c0f6314ab6814
将下载包解压到
/usr/local/python/Python-2.7.14/plugins/setuptools-37.0.0
#安装pip
[root@dev22 setuptools-37.0.0]# python setup.py install
File "/usr/local/python/Python-2.7.14/lib/python2.7/zipfile.py", line 736, in __init__
"Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
#由于没有安装zip导致
# 安装zlib
[root@dev22 Python-2.7.14]# yum install zlib zlib-devel
# 重新编译安装即可
[root@dev22 Python-2.7.14]# make
[root@dev22 Python-2.7.14]# make install
#再次安装成功
[root@dev22 setuptools-37.0.0]# python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file 'setuptools.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'setuptools/_vendor'
writing manifest file 'setuptools.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/setuptools-37.0.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing setuptools-37.0.0-py2.7.egg
Copying setuptools-37.0.0-py2.7.egg to /usr/local/python/Python-2.7.14/lib/python2.7/site-packages
Adding setuptools 37.0.0 to easy-install.pth file
Installing easy_install script to /usr/local/python/Python-2.7.14/bin
Installing easy_install-2.7 script to /usr/local/python/Python-2.7.14/bin
Installed /usr/local/python/Python-2.7.14/lib/python2.7/site-packages/setuptools-37.0.0-py2.7.egg
Processing dependencies for setuptools==37.0.0
Finished processing dependencies for setuptools==37.0.0
[root@dev22 setuptools-37.0.0]#
安装pip
下载地址:https://pypi.python.org/pypi/pip#downloads
https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
[root@dev22 pip-9.0.1]# python setup.py install
#可以看到将pip命令安装到了python的bin目录了
Installing pip script to /usr/local/python/Python-2.7.14/bin
Installing pip2.7 script to /usr/local/python/Python-2.7.14/bin
Installing pip2 script to /usr/local/python/Python-2.7.14/bin
#安装pymysql报错,找不到ssl
[root@dev22 bin]# ./pip install PyMySQL
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting PyMySQL
Could not fetch URL https://pypi.python.org/simple/pymysql/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement PyMySQL (from versions: )
No matching distribution found for PyMySQL
# 安装openssl
[root@dev22 pip-9.0.1]# yum install openssl-devel -y
# 重新编译安装python
[root@dev22 Python-2.7.14]# make
[root@dev22 Python-2.7.14]# make install
#安装pymysql
[root@dev22 bin]# ./pip install pymysql
Collecting pymysql
Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB)
100% |████████████████████████████████| 81kB 199kB/s
Installing collected packages: pymysql
Successfully installed pymysql-0.7.11
[root@dev22 bin]#
安装pymysql
mysql模块安装
下载:
https://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.7.tar.gz
#解压
[root@dev22 plugins]# tar -zxvf mysql-connector-python-2.1.7.tar.gz
[root@dev22 plugins]# cd mysql-connector-python-2.1.7
#安装
[root@dev22 mysql-connector-python-2.1.7]# python setup.py install
running install
#测试
更多推荐
所有评论(0)