cd /tools wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz
解压缩文件
1
tar -xzvf Python-3.10.8.tgz
编译安装
1 2 3 4 5 6
cd /tools/Python-3.10.8
./configure --prefix=/tools/Python-3.10.8 --enable-optimizations ./configure --prefix=/tools/Python-3.10.8 # 跳过`test`步骤. make make install
1 2 3 4 5 6
# 测试安装结果 $ ./python Python 3.10.8 (main, May 12025, 19:44:42) [GCC 9.4.0] on linux Type"help", "copyright", "credits"or"license"for more information. >>> import os >>>
configure: error: no acceptable C compiler found in $PATH
1 2 3 4 5 6 7 8 9
# ERROR: configure: error: no acceptable C compiler found in$PATH checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/root/tools/Python-3.8.3': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details $ apt-get install cmake
ModuleNotFoundError: No module named ‘zlib’
1 2 3 4 5 6 7 8 9 10 11 12
File "<frozen zipimport>", line 520, in _get_decompress_func ModuleNotFoundError: No module named 'zlib' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<frozen zipimport>", line 568, in _get_data File "<frozen zipimport>", line 523, in _get_decompress_func zipimport.ZipImportError: can't decompress data; zlib not available
# Error: ModuleNotFoundError: No module named '_ctypes' Traceback (most recent call last): File "setup.py", line 8, in <module> from setuptools import find_packages, setup File "/root/tools/Python-3.8.3/lib/python3.8/site-packages/setuptools/__init__.py", line 20, in <module> from setuptools.dist import Distribution, Feature File "/root/tools/Python-3.8.3/lib/python3.8/site-packages/setuptools/dist.py", line 35, in <module> from setuptools import windows_support File "/root/tools/Python-3.8.3/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module> import ctypes File "/root/tools/Python-3.8.3/Lib/ctypes/__init__.py", line 7, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' $ apt-get install libffi-dev
the ssl module in Python is not available
1 2 3 4 5
# WARNING: the ssl module in Python is not available WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/ $ apt-get install openssl libssl-dev
ModuleNotFoundError: No module named ‘_bz2’
1 2 3 4 5 6 7
# Error ... import bz2 File "/home/albert/mysoft/Python-3.6.8/Lib/bz2.py", line 23, in <module> from _bz2 import BZ2Compressor, BZ2Decompressor ModuleNotFoundError: No module named '_bz2' $ apt-get install libbz2-dev