centos7中安装python3.7.3

北慕城南 提交于 2021-02-12 09:18:22

环境: CentOS_7 (root用户) 软件版本: python_3.7.3


  • 安装依赖包
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
  • 解压并编译源码
tar zxvf Python-3.7.3.tgz
cd Python-3.7.3/
./configure --prefix=/usr/local/python-3.7.3
make && make install
  • 配置软链接
ln -s /usr/local/python-3.7.3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python-3.7.3/bin/pip3.7 /usr/bin/pip3
  • 验证
python3 -V

Python 3.7.3
------
pip3 -V

pip 19.0.3 from /usr/local/python-3.7.3/lib/python3.7/site-packages/pip (python 3.7)


安装最新版本django提示sqlite3版本低,需要更高版本。

###python安装高版本sqlite3

  • 安装sqlite3
yum -y install libstdc++.x86_64 glibc.i686 zlib.i686 zlib.x86_64
mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
wget https://www.sqlite.org/2019/sqlite-autoconf-3300000.tar.gz
tar zxvf sqlite-autoconf-3300000.tar.gz && cd sqlite-autoconf-3300000
./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1"
make
make install
ln -s /usr/local/sqlite3/bin/sqlite3 /usr/bin/sqlite3
  • 重新编译python
cd Python-3.7.3/
LD_RUN_PATH=/usr/local/sqlite3/lib ./configure --prefix=/usr/local/python-3.7.3 LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"
LD_RUN_PATH=/usr/local/sqlite3/lib make
LD_RUN_PATH=/usr/local/sqlite3/lib sudo make install
  • 检测python3.7中sqlite3版本
python3

>>> import sqlite3
>>> sqlite3.sqlite_version
'3.30.0'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!