Python3/pip aarch64上的離線安裝

济南小老虎發表於2024-04-05

Python3/pip aarch64上的離線安裝


背景

2021年底總結過一版本, 想著這次重新梳理一下
主要是ARM機器上面的過程.

發現裡面一個深坑. 
python3.11 跟python3.9 不一樣
無法使用libssl 和 openssl1.1.1s 
我這邊直接使用 openssl3.2.1 才可以正常編譯安裝

這一塊網上資料比較少比較坑. 

第一步下載

需要說明 2024.4時最新版本已經是python3.13了
但是為了穩定性與相容性, 我準備使用 3.11.9 的版本
之前的版本是 3.9 本次進行一次升級工作. 

wget https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz

安裝必備的依賴

yum install libffi-devel tcl-devel tk-devel perl-CPAN -y
yum groups install "Development Tools" -y
yum install openssl-devel readline-devel sqlite-devel perl-CPAN -y 
wget https://github.com/openssl/openssl/releases/download/openssl-3.2.1/openssl-3.2.1.tar.gz

tar -zxvf openssl-3.2.1.tar.gz && cd openssl-3.2.1
./config -fPIC --prefix=/opt/openssl enable-shared && make && make install

mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak

ln -s /opt/openssl/include/openssl /usr/include/openssl
ln -s /opt/openssl/lib64/libssl.so.3 /usr/local/lib64/libssl.so
ln -s /opt/openssl/bin/openssl /usr/bin/openssl

echo "/opt/openssl/lib64" >> /etc/ld.so.conf
ldconfig -v

確定版本
openssl version


打包python

tar -zxvf Python-3.11.9.tgz && cd Python-3.11.9
time ./configure --with-openssl=/opt/openssl --prefix=/opt/python3  --enable-optimizations  --with-openssl-rpath=auto OPENSSL_LDFLAGS=-L/opt/openssl   OPENSSL_LIBS=-l/opt/openssl/ssl OPENSSL_INCLUDES=-I/opt/openssl


注意需要修改 Modules/Setup的檔案
將: 
To statically link OpenSSL:

下面的四行修改為如下: 注意是取消註釋

# To statically link OpenSSL:
 _ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
     -l:libssl.a -Wl,--exclude-libs,libssl.a \
     -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
 _hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
     -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a

./configure --with-openssl=/opt/openssl --prefix=/opt/python3  --enable-optimizations

time make 

make install


修改境內源

mkdir ~/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
EOF

/opt/python3/bin/python3 -m pip install --upgrade pip

安裝pip包

/opt/python3/bin/pip3 install async-generator attrs bcrypt certifi cffi 
/opt/python3/bin/pip3 install charset-normalizer cryptography ddt et-xmlfile h11 idna jdcal Mako 
/opt/python3/bin/pip3 install MarkupSafe numpy opencv-python openpyxl outcome pandas paramiko 
/opt/python3/bin/pip3 install Pillow  PyAutoIt pycparser PyNaCl pyOpenSSL python-dateutil 
/opt/python3/bin/pip3 install pytz PyYAML requests selenium setuptools six sniffio sortedcontainers 
/opt/python3/bin/pip3 install trio trio-websocket urllib3 wsproto xlrd xlwt 
/opt/python3/bin/pip3 install psycopg2

打包python的映象檔案

cd /opt
tar -czvf  python3_aarch64_tar.gz  python3/

可以用來備用了. 

相關文章