Python Linux Edition 安装手顺
一般情况的安装:
- 背景
Linux Python例子作成时需要Python环境,需要手动安装。
- 所需材料(以Python-3.8.3为例)
Python Linux Edition :Python-3.8.3.tgz
安装OS:(文档作成时的安装OS)
Ubuntu 20.04 LTS (kernel 5.4.0-26-generic)(64bit US)
Ubuntu 18.04.3 LTS (kernel 5.0.0-23-generic)(64bit US)
Red Hat 需要自己找到rpm包进行安装,见备注。
- 安装步骤
- 安装所需lib
sudo apt-get update
sudo apt-get install zlib1g-dev
sudo apt-get install libffi-dev
-
- 安装Python-3.8.3
tar -xvf Python-3.8.3.tgz
cd Python-3.8.3
./configure
make
make test
sudo make install
-
- 运行例子以inout为例
python3 inout
- 缺少库文件时报的错误
- 缺少zlib1g-dev
在make test时有以下错误
== Tests result: FAILURE then FAILURE ==
392 tests OK.
2 tests failed:
test_importlib test_normalization
29 tests skipped:
test_bz2 test_ctypes test_curses test_dbm_gnu test_dbm_ndbm
test_devpoll test_gzip test_idle test_ioctl test_kqueue test_lzma
test_msilib test_ossaudiodev test_readline test_smtpnet
test_sqlite test_ssl test_startfile test_tcl test_tix test_tk
test_ttk_guionly test_ttk_textonly test_turtle test_winconsoleio
test_winreg test_winsound test_zipfile64 test_zlib
2 re-run tests:
test_importlib test_normalization
Total duration: 4 min 35 sec
Tests result: FAILURE then FAILURE
make: *** [Makefile:1130: test] Error 2
-
- 缺少libffi-dev
执行例子时报错:
Traceback (most recent call last):
File "inout.py", line 3, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
备注:如果先安装了Python-3.8.3再安装lib需要重新安装Python-3.8.3
一般只需要zlib1g-dev和libffi-dev两个rpm包,在此文档的同级目录中。
特殊情况的安装(RH6.0、6.7需要升级GCC):
- 安装gcc前准备
在此文档的同级目录中找到与系统对应的文件夹,将其中的rpm包拷贝到系统中。
执行以下命令安装rpm包:
rpm -ivh glibc* nss*
ldconfig (只有RH6.7 64位需要执行这两条)
- 安装gcc
由于编译Python3.9.1需要gcc版本4.6.0以上,所以gcc版本不够的话要安装gcc,Python3.10.0编译时使用gcc 4.6.0 没有问题。
-
- 将此文档的同级目录中的gcc4.6.0目录拷贝到系统下
- 进入gcc4.6.0目录
- 解压gcc-4.6.0.tar.bz2
- 进入解压后的目录gcc-4.6.0
- 将上一层的3个包拷贝到当前目录下(gmp-4.3.2.tar.bz2、mpc-0.8.1.tar.gz、mpfr-2.4.2.tar.bz2)
- 修改./contrib/download_prerequisites文件
vi ./contrib/download_prerequisites
将其中的3行开头为wget*的行使用”#”注释掉
./contrib/download_prerequisites
-
- mkdir build
- cd build
- ./../configure
- make -j4
- make install
- 安装Python依赖的库
- 安装之前拷贝到系统中的rpm包。
rpm -ivh libffi* zlib*
-
- 修改系统文件:
vi /etc/ld.so.conf
32位系统新加一行:/usr/local/lib
64位系统新加一行:/usr/local/lib64
-
- ldconfig
- 安装Python
- 将Python的Source包拷贝到系统中解压
- 进入解压后的文件夹
./configure
Python3.10.0配置时需要在后面追加参数(这是一个Bug详见:https://bugs.python.org/issue45350):
./configure PKG_CONFIG=$(which pkg-config)
-
- make
- make install
参照本文在以下环境中都可以正常安装:
如果不想去找rpm包的话可以去下载我上传的:
Python_Install_20211206.zip-Linux文档类资源-CSDN下载
RedHat Enterprise Linux 8.0 4.18.0-80.el8.x86_64
RedHat Enterprise Linux 7.2 3.10.0-327.el7.x86_64
RedHat Enterprise Linux 7.1 3.10.0-229.el7.x86_64
RedHat Enterprise Linux 7.0 3.10.0-123.el7.x86_64
RedHat Enterprise Linux 6.7 2.6.32-573.el6.x86_64
RedHat Enterprise Linux 6.7 2.6.32-573.el6.i686
RedHat Enterprise Linux 6.0 2.6.32-71.el6.i686
Ubuntu 20.04.2 LTS 5.8.0-43-generic (x86_64)
Ubuntu 20.04 LTS 5.4.0-26-generic (x86_64)
Ubuntu 18.04.3 LTS 5.0.0-23-generic (x86_64)
Ubuntu 18.04.1 LTS 4.15.0-29-generic (x86_64)
Ubuntu 16.04.1 LTS 4.4.0-31-generic (x86_64)
Ubuntu 14.04.3 LTS 3.19.0-25-generic (x86_64)
Ubuntu 16.04.5 LTS 4.15.0-29-generic (i686)
Ubuntu 16.04.1 LTS 4.4.0-31-generic (i686)
Ubuntu 14.04.3 LTS 3.19.0-25-generic (i686)
董世博
2021/12/03