-1

我刚刚注意到我不能再使用 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 坏了?

更新

  1. 用 Python 2.7 alpha dll 试过这个,它似乎可以工作,所以它可能是 2.6 的问题。
  2. 在带有 Python 2.7 alpha 的 Ubuntu x64 上进行了尝试,并且没有出现分段错误。
4

2 回答 2

2

你在做什么是错误的。您显然正在运行 Python 2.6,然后尝试在同一进程(和线程)中初始化共享库,这将崩溃(如果幸运的话......之后)。您永远不应该尝试将 Python 加载到自身并调用 Py_Initialize。

于 2009-12-26T07:06:45.013 回答
1

好吧,我怀疑你能做的是在同一个进程中同时加载2.5和 2.6 ...... ctypes.cdll.python26.Py_Initialize() 单独工作吗?

编辑:等等,您是否尝试从 Python 本身加载 Python DLL?有什么?

于 2009-12-26T03:49:22.600 回答