dxbjfu0 2019-06-21
1、CentOS安装Python的依赖包
yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、下载Python2.7.13的源码包并编译
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz tar xf Python-2.7.13.tgz cd Python-2.7.13 ./configure --prefix=/usr/local make make install
可能出现的异常:
import sqlite3时抛出异常:ModuleNotFoundError: No module named '_sqlite3'
没有安装pip
1.import sqlite3时抛出异常:ModuleNotFoundError: No module named '_sqlite3'
yum install --installroot=/usr/local/ sqlite3
修改python setup.py文件
cd Python-2.7.13 vi ./setup.py
sqlite_inc_paths = [ '/usr/include', '/usr/local/sqlite3/include', #增加该部分内容 '/usr/include/sqlite', '/usr/include/sqlite3', '/usr/local/include', '/usr/local/include/sqlite', '/usr/local/include/sqlite3',]
然后重新编译就可以了。
2.没有安装pip
# 安装Pip wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz tar -vxf setuptools-1.4.2.tar.gz cd setuptools-1.4.2 python2.7 setup.py install # 若系统默认的为python2.7可以直接使用python easy_install-2.7 pip