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

import zlib error when cross compiling python for arm

我正在为 arm 编译 python,在我的 ubuntu 虚拟框中。在所有这些步骤 运行 之后,我将 python 放在带有 arm 处理器的机器上。我在终端中 运行 命令 "python" 并收到一条错误消息,指出它无法导入 zlib。我一直在网上尝试许多解决方案,none 对我有用。唉,我最后的希望就是在这里尝试 post 这个问题。当这条线时,我能够让它在目标机器上工作:

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。我正在 运行ning Ubuntu 12.04.5.The 以下是我正在采取的步骤...

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 文件。