gpt4 book ai didi

python - 交叉编译python for arm时导入zlib错误

转载 作者:行者123 更新时间:2023-12-04 18:51:29 24 4
gpt4 key购买 nike

我正在为 arm 编译 python,在我的 ubuntu 上的虚拟框中。在所有这些步骤运行之后,我将 python 放在带有 arm 处理器的机器上。我在终端中运行命令“python”,我得到一个错误,说它不能导入 zlib。我一直在在线尝试许多解决方案,但没有一个对我有用。唉,我最后的希望是试图在这里发布这个问题。当这条线时,我能够让它在目标机器上工作:

rm -r lib2to3 idlelib lib-tk site-packages config lib-dynload

是这样写的:
rm -r lib2to3 idlelib lib-tk site-packages config lib-dynload distutils

我需要 distutils 因为我正在尝试在机器上安装 pip。我无法做到,因为我相信 distutils 依赖于 zlib,但是在为目标机器交叉编译后,我无法让 python 找到 zlib。我正在运行 Ubuntu 12.04.5。以下是我正在采取的步骤...
mkdir -p pybuild
cd pybuild

# download arm-fsl toolchain
git clone git@github.com:embeddedarm/linux-2.6.35.3-imx28.git

# set path variables
export PATH=$PATH:`pwd`/linux-2.6.35.3-imx28/cross-toolchain/arm-fsl-linux-gnueabi/bin/
export BASE_PYTHON_COMPILATION_PATH=`pwd`

# sqlite3 headers
wget http://backports.debian.org/debian-backports/pool/main/s/sqlite3/libsqlite3-dev_3.7.13-1~bpo60+1_armel.deb
ar vx libsqlite3-dev_3.7.13-1~bpo60+1_armel.deb
tar xzf data.tar.gz
mv usr/* .

# zlib
wget http://www.gzip.org/zlib/zlib-1.1.4.tar.gz
tar xvf zlib-1.1.4.tar.gz
cd zlib-1.1.4
CC=arm-fsl-linux-gnueabi-gcc \
LDSHARED="arm-fsl-linux-gnueabi-gcc -shared -Wl,-soname,libz.so.1" \
./configure --shared --prefix=$BASE_PYTHON_COMPILATION_PATH
make
make install
cd ..

# openssl
wget https://www.openssl.org/source/openssl-1.0.1i.tar.gz
tar xvf openssl-1.0.1i.tar.gz
cd openssl-1.0.1i
./Configure dist --prefix=$BASE_PYTHON_COMPILATION_PATH
make CC="arm-fsl-linux-gnueabi-gcc" AR="arm-fsl-linux-gnueabi-ar r" RANLIB="arm-fsl-linux-gnueabi-ranlib"
make install
cd ..

# python dependencies
wget https://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xvzf Python-2.7.3.tgz
cd Python-2.7.3

# build for the host system
./configure
make python Parser/pgen
mv python hostpython
mv Parser/pgen Parser/hostpgen
make distclean

# patch it up
wget http://randomsplat.com/wp-content/uploads/2012/10/Python-2.7.3-xcompile.patch
patch -p1 < Python-2.7.3-xcompile.patch

# configure
CC=arm-fsl-linux-gnueabi-gcc \
CXX=arm-fsl-linux-gnueabi-g++ \
AR=arm-fsl-linux-gnueabi-ar \
RANLIB=arm-fsl-linux-gnueabi-ranlib \
PYTHON_XCOMPILE_DEPENDENCIES_PREFIX=$BASE_PYTHON_COMPILATION_PATH \
./configure --host=arm-linux --build=i686-pc-linux-gnu --prefix=$BASE_PYTHON_COMPILATION_PATH/tmp

# build
make clean
make HOSTPYTHON=./hostpython \
PYTHON_XCOMPILE_DEPENDENCIES_PREFIX=$BASE_PYTHON_COMPILATION_PATH \
HOSTPGEN=./Parser/hostpgen \
BLDSHARED="arm-fsl-linux-gnueabi-gcc -shared" \
HOSTARCH=arm-linux \
BUILDARCH=x86_64-linux-gnu \
CROSS_COMPILE=arm-fsl-linux-gnueabi- \
CROSS_COMPILE_TARGET=yes | tee make.log 2>&1

# "install"
make install HOSTPYTHON=./hostpython \
BLDSHARED="arm-fsl-linux-gnueabi-gcc -shared" \
HOSTARCH=arm-linux \
BUILDARCH=x86_64-linux-gnu \
CROSS_COMPILE=arm-fsl-linux-gnueabi- \
CROSS_COMPILE_TARGET=yes prefix=$BASE_PYTHON_COMPILATION_PATH/Python- 2.7.3/_install | tee install.log 2>&1

# create a target directory for a minimal version of the installation
cd $BASE_PYTHON_COMPILATION_PATH/Python-2.7.3/
rm -r _install_minimal
mkdir -p _install_minimal/bin
mkdir -p _install_minimal/usr/lib/python2.7
mkdir -p _install_minimal/usr/include

# copy in the python binary file
cd $BASE_PYTHON_COMPILATION_PATH/Python-2.7.3/
cp _install/bin/python2.7 _install_minimal/bin/python

# bundle up the lib files into a zip file, after removing unneeded bits
cd $BASE_PYTHON_COMPILATION_PATH/Python-2.7.3/_install/lib/
rm -r python2.7-minimal
cp -r python2.7 python2.7-minimal
cd python2.7-minimal
rm -r lib2to3 idlelib lib-tk site-packages config lib-dynload
rm *.doc *.txt
rm -r `find -name "test"`
zip -r -y python27.zip .

# copy in the python library files
cd $BASE_PYTHON_COMPILATION_PATH/Python-2.7.3
cp _install/lib/python2.7-minimal/python27.zip _install_minimal/usr/lib/
cp -r _install/lib/python2.7/config _install_minimal/usr/lib/python2.7/
cp -r _install/lib/python2.7/lib-dynload _install_minimal/usr/lib/python2.7/
cp -r _install/lib/python2.7/site-packages _install_minimal/usr/lib/python2.7/
cp -r _install/include/python2.7 _install_minimal/usr/include/
cd _install_minimal
rm ../../python.zip
zip -r ../../python.zip .
cd ../../..

echo "Compilation complete (hopefully successfully). Now, connect to the Sandisk device's wifi hotspot,"
echo "and then run the local ./upload_python.sh script."

最佳答案

所以我弄清楚出了什么问题。我变了

rm -r lib2to3 idlelib lib-tk site-packages config lib-dynload


rm -r site-packages config lib-dynload

此外,无论何时运行构建脚本,请务必在每次运行开始时删除 pybuild 目录。在随后的运行中,由于 pybuild 目录仍然存在,它会出于某种原因删除 .so 文件。

关于python - 交叉编译python for arm时导入zlib错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32870211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com