环境
主机: ubuntu14.04 64bit
开发板: qemu + vexpress-a9 (参考: http://www.cnblogs.com/pengdonglin137/p/6442583.html)
工具链: arm-none-linux-gnueabi-gcc (gcc version 4.8.3 20140320)
Python版本: Python-2.7.13
前面一篇博文(交叉编译Python-2.7.13到ARM(aarch32)平台)介绍了移植python到aarch32上面,但是发现有很多模块都不能用,可以在板子上面执行下面的命令测试一下:
1 [root@vexpress ]# python /usr/lib/python2.7/test/test___all__.py
2 Traceback (most recent call last):
3 File "/usr/lib/python2.7/test/test___all__.py", line 3, in
4 import unittest
5 File "/usr/lib/python2.7/unittest/__init__.py", line 58, in
6 from .result import TestResult
7 File "/usr/lib/python2.7/unittest/result.py", line 9, in
8 from . import util
9 File "/usr/lib/python2.7/unittest/util.py", line 2, in
10 from collections import namedtuple, OrderedDict
11 File "/usr/lib/python2.7/collections.py", line 20, in
12 from _collections import deque, defaultdict
13 ImportError: No module named _collections
可以看到这里找不到_collections模块。
对比x86_64的编译结果:
1 ls x86_64/build/lib.linux-x86_64-2.7/
2 array.so* _codecs_hk.so* cPickle.so* _curses_panel.so* future_builtins.so* itertools.so* mmap.so* parser.so* _socket.so* _sysconfigdata.py time.so*
3 audioop.so* _codecs_iso2022.so* crypt.so* _curses.so* grp.so* _json.so* _multibytecodec.so* pyexpat.so* spwd.so* _sysconfigdata.pyc unicodedata.so*
4 binascii.so* _codecs_jp.so* cStringIO.so* datetime.so* _hashlib.so* linuxaudiodev.so* _multiprocessing.so* _random.so* _sqlite3.so* _sysconfigdata.pyo zlib.so*
5 _bisect.so* _codecs_kr.so* _csv.so* _elementtree.so* _heapq.so* _locale.so* nis.so* readline.so* _ssl.so* syslog.so*
6 cmath.so* _codecs_tw.so* _ctypes.so* fcntl.so* _hotshot.so* _lsprof.so* operator.so* resource.so* strop.so* termios.so*
7 _codecs_cn.so* _collections.so* _ctypes_test.so* _functools.so* _io.so* math.so* ossaudiodev.so* select.so* _struct.so* _testcapi.so*
而aarch32的编译结果:
1 $ls aarch32/build/lib.linux2-arm-2.7/
2 audioop.so* _codecs_iso2022.so* _codecs_tw.so* _ctypes.so* _elementtree.so* _json.so* mmap.so* nis.so* resource.so* termios.so*
3 _codecs_cn.so* _codecs_jp.so* crypt.so* _ctypes_test.so* future_builtins.so* linuxaudiodev.so* _multibytecodec.so* parser.so* _sysconfigdata.py _testcapi.so*
4 _codecs_hk.so* _codecs_kr.so* _csv.so* datetime.so* _hotshot.so* _lsprof.so* _multiprocessing.so* pyexpat.so* _sysconfigdata.pyc
可以看到,aarch32上面缺少了很多库, 比如_collections.so,将来这些库会被安装到/usr/lib/python2.7/lib-dynload下面, 所以下面要说的就是将缺少的这些库弄回来!
正文
1、通过分析setup.py发现问题
在函数build_extensions中刚开始self.extensions中存放的是需要编译库, 通过在加打印:
1 diff --git a/setup.py b/setup.py
2 index 54054c2..bc16bb1 100644
3 --- a/setup.py
4 +++ b/setup.py
5 @@ -178,6 +178,7 @@ class PyBuildExt(build_ext):
6
7 def build_extensions(self):
8
9 + print "build_extensions enter."
10 # Detect which modules should be compiled
11 missing = self.detect_modules()
12
13 @@ -191,6 +192,9 @@ class PyBuildExt(build_ext):
14 extensions.append(ctypes)
15 self.extensions = extensions
16
17 + for ext in self.extensions:
18 + print "extensions: ", ext.name
19 +
20 # Fix up the autodetected modules, prefixing all the source files
21 # with Modules/ and adding Python's include directory to the path.
22 (srcdir,) = sysconfig.get_config_vars('srcdir')
23 @@ -217,6 +221,8 @@ class PyBuildExt(build_ext):
24 # Python header files
25 headers = [sysconfig.get_config_h_filename()]
26 headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
27 +
28 + print "builtin_module_names: ", sys.builtin_module_names
29 for ext in self.extensions[:]:
30 ext.sources = [ find_module_file(filename, moddirlist)
31 for filename in ext.sources ]
32 @@ -248,10 +254,15 @@ class PyBuildExt(build_ext):
33 remove_modules.append(line[0])
34 input.close()
35
36 + print "remove_modules: ", remove_modules
37 +
38 for ext in self.extensions[:]:
39 if ext.name in remove_modules:
40 self.extensions.remove(ext)
41
42 + for ext in self.extensions[:]:
43 + print "extensions: ", ext.name
44 +
45 # When you run "make CC=altcc" or something similar, you really want
46 # those environment variables passed into the setup.py phase. Here's
47 # a small set of useful ones.
48 @@ -1618,13 +1629,13 @@ class PyBuildExt(build_ext):
49
50
51 # Platform-specific libraries
52 - if host_platform == 'linux2':
53 + if host_platform == 'linux2' or host_platform == 'linux2-arm':
54 # Linux-specific modules
55 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
56 else:
57 missing.append('linuxaudiodev')
58
59 - if (host_platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
60 + if (host_platform in ('linux2','linux2-arm' 'freebsd4', 'freebsd5', 'freebsd6',
61 'freebsd7', 'freebsd8')
62 or host_platform.startswith("gnukfreebsd")):
63 exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
64 @@ -1755,6 +1766,10 @@ class PyBuildExt(build_ext):
65 ## ext = Extension('xx', ['xxmodule.c'])
66 ## self.extensions.append(ext)
67
68 +# print "missing: ", missing
69 +# for ext in self.extensions:
70 +# print "extensions: ", ext.name
71 +
72 return missing
73
74 def detect_tkinter_explicitly(self):
75 @@ -2229,6 +2244,8 @@ Topic :: Software Development
76 """
77
78 def main():
79 + print "sys.path: ", sys.path
80 + print "cross_compiling: ", cross_compiling
81 # turn off warnings when deprecated modules are imported
82
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』