apt install python3-dev python3 python3-venv
yum install python38-devel
Python源码地址:https://www.python.org/downloads/source/
tar -zxvf Python-3.8.18.tgz
mkdir /usr/local/Python38
cd Python-3.8.18
./configure --prefix=/usr/local/python38
make -j 8 && make install
ln -s /usr/local/python38/bin/python3.8 /usr/bin/python
ln -s /usr/local/python38/bin/pip3 /usr/bin/pip
有网的环境直接用pip,方便快捷:
pip install xxx
没网的情况下,可以去官网搜索需要的python库下载对应的whl文件进行安装。注意,此时下载的whl安装包一定要是符合自己Python版本和系统处理器位数的版本,下载的库名中cp39代表python3.9版本,想知道系统具体可以安装哪些标签的.whl文件,可以使用pip debug --verbose,兼容的文件标签就会显示。
[fakerth@localhost ~]$ pip debug --verbose
pip version: pip 23.0.1 from /usr/local/python38/lib/python3.8/site-packages/pip (python 3.8)
sys.version: 3.8.18 (default, Nov 17 2023, 18:40:57)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-20)]
sys.executable: /usr/local/python38/bin/python3.8
sys.getdefaultencoding: utf-8
sys.getfilesystemencoding: utf-8
locale.getpreferredencoding: UTF-8
sys.platform: linux
sys.implementation:
name: cpython
'cert' config value: Not specified
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
pip._vendor.certifi.where(): /usr/local/python38/lib/python3.8/site-packages/pip/_vendor/certifi/cacert.pem
pip._vendor.DEBUNDLED: False
vendored library versions:
CacheControl==0.12.11
colorama==0.4.6
distlib==0.3.6
distro==1.8.0
msgpack==1.0.4
packaging==21.3
platformdirs==2.6.2
pyparsing==3.0.9
pyproject-hooks==1.0.0
requests==2.28.2
certifi==2022.12.07
chardet==5.1.0
idna==3.4
urllib3==1.26.14
rich==12.6.0 (Unable to locate actual module version, using vendor.txt specified version)
pygments==2.13.0
typing_extensions==4.4.0 (Unable to locate actual module version, using vendor.txt specified version)
resolvelib==0.8.1
setuptools==44.0.0 (Unable to locate actual module version, using vendor.txt specified version)
six==1.16.0
tenacity==8.1.0 (Unable to locate actual module version, using vendor.txt specified version)
tomli==2.0.1
webencodings==0.5.1 (Unable to locate actual module version, using vendor.txt specified version)
Compatible tags: 543
cp38-cp38-manylinux_2_28_x86_64
cp38-cp38-manylinux_2_27_x86_64
cp38-cp38-manylinux_2_26_x86_64
cp38-cp38-manylinux_2_25_x86_64
cp38-cp38-manylinux_2_24_x86_64
cp38-cp38-manylinux_2_23_x86_64
cp38-cp38-manylinux_2_22_x86_64
cp38-cp38-manylinux_2_21_x86_64
cp38-cp38-manylinux_2_20_x86_64
cp38-cp38-manylinux_2_19_x86_64
cp38-cp38-manylinux_2_18_x86_64
cp38-cp38-manylinux_2_17_x86_64
cp38-cp38-manylinux2014_x86_64
cp38-cp38-manylinux_2_16_x86_64
cp38-cp38-manylinux_2_15_x86_64
cp38-cp38-manylinux_2_14_x86_64
cp38-cp38-manylinux_2_13_x86_64
cp38-cp38-manylinux_2_12_x86_64
cp38-cp38-manylinux2010_x86_64
cp38-cp38-manylinux_2_11_x86_64
cp38-cp38-manylinux_2_10_x86_64
cp38-cp38-manylinux_2_9_x86_64
cp38-cp38-manylinux_2_8_x86_64
cp38-cp38-manylinux_2_7_x86_64
cp38-cp38-manylinux_2_6_x86_64
cp38-cp38-manylinux_2_5_x86_64
cp38-cp38-manylinux1_x86_64
cp38-cp38-linux_x86_64
cp38-abi3-manylinux_2_28_x86_64
cp38-abi3-manylinux_2_27_x86_64
cp38-abi3-manylinux_2_26_x86_64
cp38-abi3-manylinux_2_25_x86_64
cp38-abi3-manylinux_2_24_x86_64
cp38-abi3-manylinux_2_23_x86_64
cp38-abi3-manylinux_2_22_x86_64
cp38-abi3-manylinux_2_21_x86_64
cp38-abi3-manylinux_2_20_x86_64
cp38-abi3-manylinux_2_19_x86_64
cp38-abi3-manylinux_2_18_x86_64
cp38-abi3-manylinux_2_17_x86_64
cp38-abi3-manylinux2014_x86_64
cp38-abi3-manylinux_2_16_x86_64
cp38-abi3-manylinux_2_15_x86_64
cp38-abi3-manylinux_2_14_x86_64
cp38-abi3-manylinux_2_13_x86_64
cp38-abi3-manylinux_2_12_x86_64
...
官网地址:https://pypi.org/
最后一步,安装:
pip install xxxx.whl
configure: error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================
See `config.log' for more details
明明有python,为什么还会报这个错误呢?解决方法:安装python-dev。正常可以使用yum或者apt-get命令直接安装python-dev,但如果没有网络,就使用如上的源码下载即可。
当使用pip install安装python库时,这个错误不期而遇。网上有很多用yum或者apt-get安装openssl或者openssl-dev,不如用源码安装openssl,一次解决问题:
wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz --no-check-certificate 下载openssl1.1.1
tar -zxf openssl-1.1.1n.tar.gz
cd openssl-1.1.1n
./config --prefix=/usr/local/openssl
make -j && make install
openssl version
安装完成后记得重新编译安装python:
./configure --prefix=/usr/local/python38 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto
make && make install
解决方法,安装bzip2和bzip2-devel后重新编译python:
yum install bzip2 bzip2-devel
./configure --prefix=/usr/local/python38 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto
make && make install
yum install perl
yum -y install autoconf automake libtool
yum -y install mpich*
echo "export PATH=$PATH:/usr/lib64/mpich/bin/" >> /root/.bashrc
source /root/.bashrc
pip install xxx
加上–no-deps治标不治本,缺少的typing-extensions也要安装。
pip install --no-deps xxxxx-cp37-cp37m-linux_x86_64.whl