centos7 install python3.10.7
编译安装openssl-1.1.1q
| Bash |
|---|
| cd /opt/
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz --no-check-certificate
tar zxf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config --prefix=/usr/local/openssl-1.1.1
make -j8
make install
|
编译安装Python-3.10.7
| Bash |
|---|
| wget https://www.python.org/ftp/python/3.10.7/Python-3.10.7.tgz
tar zxf Python-3.10.7.tgz
cd Python-3.10.7
./configure --prefix=/usr/local/python3.10.7 --with-openssl=/usr/local/openssl-1.1.1 --with-openssl-rpath=auto
make -j8
make install
|
编译安装Python-3.10.0
| Bash |
|---|
| wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
tar zxf Python-3.10.0.tgz
cd Python-3.10.0
./configure --prefix=/usr/local/python3.10 --with-openssl=/usr/local/openssl-1.1.1 --with-openssl-rpath=auto
make -j8
make install
|
官方文档有提到加--enable-optimizations参数可以提升后期python百分之10的运行速度,不过我加上后发现会编译失败
解决方式网友提出两种:
- 升级
gcc版本
- 删除--enable-optimizations项
我不是很在于python的性能,所以采用了删除--enable-optimizations项来解决编译问题。你们可以尝试使用升级gcc的方式。
异常解决
make 编译安装时异常
| Bash |
|---|
| Could not import runpy module
Traceback (most recent call last):
File "/usr/local/lib/python/3.8.3/Lib/runpy.py", line 15, in <module>
import importlib.util
File "/usr/local/lib/python/3.8.3/Lib/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/usr/local/lib/python/3.8.3/Lib/contextlib.py", line 4, in <module>
import _collections_abc
SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
make[1]: *** [pybuilddir.txt] Error 1
make[1]: Leaving directory `/usr/local/lib/python/3.8.3'
make: *** [profile-opt] Error 2
|
原因:可能是 gcc 版本太低的问题
解决方法:
1、安装scl源
yum install centos-release-scl
2、安装 gcc、gcc+
yum install devtoolset-7-gcc devtoolset-7-gcc-c++
3、启动:
scl enable devtoolset-7 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。如果要长期使用gcc 7.3的话:
echo "source /opt/rh/devtoolset-7/enable" >>/etc/profile
4、查看版本: