您根本无法将32位代码加载到64位应用程序中,反之亦然。您的选择是:切换到使用32位解释器
继续使用64位解释器,但要使用multiprocessing以便允许64位解释器与32位解释器通信。在
将32位库重新编译为64位库
前两个选项有一个问题,即在基于debian的发行版上,不能使用包管理器同时安装32位解释器和64位解释器(参见eryksun的评论)。在
重新编译库几乎肯定是更容易的选择,而且绝对不会带来运行时开销。在
一个如何做数字(2)的例子。预先警告:如果您经常使用这些方法,或者使用大量的输入/输出,这将导致来回发送数据的高开销。在
在主.py在# example using the standard c library
from subprocess import Popen, PIPE
from multiprocessing.managers import BaseManager
import atexit
p = Popen(["/path/to/32-bit/python", "/path/to/delegate.py"], stdout=PIPE)
atexit.register(p.terminate)
port = int(p.stdout.readline())
authkey = p.stdout.read()
m = BaseManager(address=("localhost", port), authkey=authkey)
m.connect()
# tell manager to expect an attribute called LibC
m.register("LibC")
# access and use libc
libc = m.LibC()
print(libc.abs(-2))
代理.py在
^{pr2}$