我刚刚注意到我不能再使用 Python 2.6 dll。Python 2.5 工作得很好。
import ctypes
py1 = ctypes.cdll.python25
py2 = ctypes.cdll.python26
# ctypes.cdll.LoadLibrary("libpython2.6.so") in linux
py1.Py_Initialize()
py2.Py_Initialize()
# segmentation fault in Linux
py1.PyRun_SimpleString("print 'hello world'")
# this works because it is using python 2.5
py2.PyRun_SimpleString("print 'hello world2'")
# WindowsError: exception: access violation reading 0x00000004
我做错了什么还是 Python 2.6 坏了?
更新
- 用 Python 2.7 alpha dll 试过这个,它似乎可以工作,所以它可能是 2.6 的问题。
- 在带有 Python 2.7 alpha 的 Ubuntu x64 上进行了尝试,并且没有出现分段错误。