python 交叉编译

2023年 10月 11日 27.7k 0

源码交叉编译p ython****

一、 编译前准备

1) 安装gcc

2) 安装交叉编译器,如arm-linux-gnueabihf-gcc

 

二、 安装libffi

1) 安装linux版libffi

sudo apt-get install libffi-dev

 

2) 安装arm版libffi

tar -xzvf libffi-3.2.1.tar.gz

mv libffi-3.2.1 libffi-3.2.1-target

cd libffi-3.2.1-target

export CC=arm-linux-gnueabihf-gcc

./configure CC=arm-linux-gnueabihf-gcc --host=arm-linux-gnueabihf --build=x86_64-linux-gnu target=arm-linux-gnueabihf --enable-shared --prefix=/home/david/libffi-3.2.1-target/libffi-target

  make && make install

 

三、 安装openssl

1) 安装linux版openssl

tar -xzvf openssl-1.0.2g.tar.gz

mv openssl-1.0.2g openssl-1.0.2g-build

cd openssl-1.0.2g-build

./config --prefix=/home/david/openssl-1.0.2g-build/openssl-build

make && make install

 

2) 安装arm版openssl

 

tar -xzvf openssl-1.0.2g.tar.gz

mv openssl-1.0.2g openssl-1.0.2g-target

cd openssl-1.0.2g-target

./config no-asm --shared --cross-compile-prefix=arm-linux-gnueabihf- --prefix=/home/david/openssl-1.0.2g-target/openssl-target

make depend

sed -i 's/-m64//' Makefile

make && make install

 

四、 安装zlib

1) 安装linux版zlib

tar -xzvf zlib-1.2.11.tar.gz

mv zlib-1.2.11 zlib-1.2.11-build

cd zlib-1.2.11-build

./configure --prefix=/home/david/zlib-1.2.11-build

make && make install

 

2) 安装arm版zlib

tar -xzvf zlib-1.2.11.tar.gz

mv zlib-1.2.11 zlib-1.2.11-target

cd zlib-1.2.11-target

./configure --prefix=/home/david/zlib-1.2.11-target/zlib-target --enable-shared

make && make install

 

五、 安装python

1) 安装linux版python

tar xvf Python-3.7.10.tgz

mv Python-3.7.10 Python-3.7.10-build

cd Python-3.7.10-build

vim Modules/Setup.dist

修改211行如下图所示

python 交叉编译-1 

修改338行如下图所示

python 交叉编译-1 

 

./configure --prefix=/home/david/Python-3.7.10-build --without-ensurepip

make && make install

cd /home/david/Python-3.7.10-build/bin

复制get-pip.py文件到此目录下

./python3 get-pip.py 或 ./python3 get-pip.py -i pypi.douban.com/simple --tr…

ln -s /home/david/Python-3.7.10-build/bin/python3 /usr/bin/python3

ln –s /usr/bin/python3 /usr/bin/python

ln -s /home/david/Python-3.7.10-build/bin/pip3 /usr/bin/pip3

ln –s /usr/bin/pip3 /usr/bin/pip

pip3 install Cython

 

2) 编译arm版python

tar xvf Python-3.7.10.tgz

mv Python-3.7.10 Python-3.7.10-target

cd Python-3.7.10-target

mkdir /home/david/python-target

cp -rfp /home/david/zlib-1.2.11-target/zlib-target/* /home/david/python-target/

cp -rfp /home/david/libffi-3.2.1-target/libffi-target/* /home/david/python-target/

cp -rfp /home/david/openssl-1.0.2g-target/openssl-target/* /home/david/python-target/

 

中间有一步配置CFLAGS和LDFLAGS,但是没有顺利编译出来,这一步存疑,暂且记录下来

export CFLAGS="-I/home/david/python-target/include -I/home/david/Python-3.7.10-build/include/python3.7m -L/home/david/python-target/lib"

export LDFLAGS="-L/home/david/python-target/lib"

 

./configure CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar RANLIB=arm-linux-gnueabihf-ranlib --host=arm-linux-gnueabihf --build=x86_64-linux-gnu --target=arm-linux-gnueabihf --disable-ipv6 ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=yes --prefix=/home/david/python-target --without-ensurepip

修改211行如下图所示

python 交叉编译-1 

修改338行如下图所示

python 交叉编译-1 

make HOSTPYTHON=/home/david/Python-3.7.10-build/bin/python3 HOSTPGEN=/home/david/Python-3.7.10-build/Parser/pgen

make install HOSTPYTHON=/home/david/Python-3.7.10-build/bin/python3

 

六、 安装到arm开发板

tar cvfz python-target.tgz python-target

复制到arm开发板上后解压,然后进入python-target/bin目录,输入python3,测试python是否能运行;

复制get-pip.py后,执行./python3 get-pip.py来安装pip3

再配置pip源

mkdir ~/.pip

vi ~/.pip/pip.conf

添加如下内容

[global]

index-url = pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论