views:

176

answers:

2

I just noticed that I cannot use the Python 2.6 dll anymore. Python 2.5 works just fine.

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

Am I doing anything wrong or is Python 2.6 broken?

Update

  1. Tried this with the Python 2.7 alpha dll and it appears to work, so it may be a 2.6 problem.
  2. Tried this on Ubuntu x64 with Python 2.7 alpha and it worked without a segmentation fault.
+1  A: 

Well, what I doubt you can do is load both 2.5 and 2.6 in the same process... Does ctypes.cdll.python26.Py_Initialize() alone work?

EDIT: wait, are you trying to load Python DLL from inside Python itself? wth?

Nicolás
+2  A: 

What you are doing is wrong. You are clearly running Python 2.6 and then trying to initialize the shared library in the same process (and thread), which is going to crash (if you're lucky...if you're not it's going to cause you very ugly trouble later). You should never, ever, try to load Python into itself and call Py_Initialize.

Nick Bastin