交叉编译python3.2

最近由于工作需要,在tcc8900的板子上面交叉编译了python3.2

为了备忘和有需要的朋友参考,将步骤记录下来;

首先都是需要下载http://www.python.org/ftp/python/

对应版本;Python-3.2.2.tar.bz2

然后执行:

tar -xvzf Python-3.2.2..tarbz2

cd Python-3.2.2

. /configure

make python Parser /pgen

mv python hostpython

mv Parser /pgen Parser /hostpgen

make distclean
下载对应的补丁文件,打上补丁:

patch -p1 < Python-2.7.2-xcompile.patch

交叉编译:

#!/bin/sh
#CC=arm-none-linux-gnueabi-gcc \
#CXX=arm-none-linux-gnueabi-g++ \
#AR=arm-none-linux-gnueabi-ar \
#RANLIB=arm-none-linux-gnueabi-ranlib \
#./configure -host=arm-none-linux-gnueabi -build=i686-pc-linux-gnu -prefix=/home/wy/Python-3.2.2/_install


#make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=x86_64-linux-gnu


make install HOSTPYTHON=./hostpython BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=~/Python-3.2.2/_install

以上是我的环境的设置;

这时候就能在指定目录找到生成的目标文件了

包括四个目录:

bin  include  lib  share

将这些文件通过nfs挂载到目标板,但是有时候目标板的速度太慢;

还是下载的执行速度跨一些啊;

接下来就是设置环境变量了;

这一步是关键,我就是在这里忙了一天,

呵呵,最后还是错误提醒了我啊


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

export PYTHONHOME=/mnt/lib/python3.2
export PYTHONPATH=.:$PYTHONHOME:$PYTHONHOME/lib
export PATH=$PATH:$PYTHONHOME:$PYTHONPATH 
export PATH=$PATH:$PYTHONHOME:$PYTHONPATH:/mnt/bin


7:设置了环境变量,运行
/mnt/lib/python3.2 # python3
Fatal Python error: Py_Initialize: Unable to get the locale encoding
EOFError: EOF read where not expected
Aborted
使用
python3 -v
可以看到 
./encodings/__pycache__/__init__.python-32.pyc has bad magic的问题
将该文件备份,删除
出现下面的新问题
/mnt/lib/python3.2 # python3
Traceback (most recent call last):
  File "/mnt/lib/python3.2/sysconfig.py", line 334, in _init_posix
    _parse_makefile(makefile, vars)
  File "/mnt/lib/python3.2/sysconfig.py", line 220, in _parse_makefile
    with open(filename, errors="surrogateescape") as f:
IOError: [Errno 2] No such file or directory: '/mnt/lib/python3.2/lib/python3.2/
config-3.2m/Makefile'


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "./site.py", line 529, in
    main()
  File "./site.py", line 517, in main
    known_paths = addusersitepackages(known_paths)
  File "./site.py", line 263, in addusersitepackages
    user_site = getusersitepackages()
  File "./site.py", line 238, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "./site.py", line 228, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/mnt/lib/python3.2/sysconfig.py", line 577, in get_config_var
    return get_config_vars().get(name)
  File "/mnt/lib/python3.2/sysconfig.py", line 474, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/mnt/lib/python3.2/sysconfig.py", line 339, in _init_posix
    raise IOError(msg)
IOError: invalid Python installation: unable to open /mnt/lib/python3.2/lib/pyth
on3.2/config-3.2m/Makefile (No such file or directory)

继续调试:
通过上面的问题看出是路径的问题,重新设置环境变量
export PYTHONHOME=/mnt
可以了 
高兴

你可能感兴趣的:(ubuntu)