SystemError: _PyImport_FixupExtension: module _types not loaded
I'm a newbie with hopefully an easy question. I'm trying to write some "C" code that will run a python script that can in turn call some "C" functions. However I'm having a problem getting started because although I can run a script from the python ide that imports ctypes, when I execute that 'import ctypes' code from the "C" code I get the following error: 'import site' failed; use -v for traceback Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\ctypes\__init__.py", line 6, in import os as _os, sys as _sys File "C:\Python25\lib\os.py", line 690, in import copy_reg as _copy_reg File "C:\Python25\lib\copy_reg.py", line 7, in from types import ClassType as _ClassType File "C:\Python25\lib\types.py", line 93, in import _types SystemError: _PyImport_FixupExtension: module _types not loaded [6569 refs] For reference here is my code: // pytest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "python.h" int _tmain(int argc, _TCHAR* argv[]) { Py_Initialize(); PyRun_SimpleString("import ctypes"); Py_Finalize(); return 0; } Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: SystemError: _PyImport_FixupExtension: module _types not loaded
On Feb 12, 2:25 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 12 Feb 2007 15:44:36 -0300, <[EMAIL PROTECTED]> escribió: > > > I'm trying to write some "C" code that will run a python script that > > can in turn call some "C" functions. However I'm having a problem > > getting started because although I can run a script from the python > > ide that imports ctypes, when I execute that 'import ctypes' code from > > the "C" code I get the following error: > > > 'import site' failed; use -v for traceback > > You have to fix this first. Probably you can't import anything, not just > ctypes. > Quoting myself from a similar problem: > > Try this: > PyRun_SimpleString("import sys; print sys.path"); > to see where Python expects to find its library (or call the Py_GetPath > function). > You may need to call Py_SetProgramName (before Py_Initialize) so it can > find where the standard library resides. > At least for testing purposes, you can copy your executable into the same > directory where Python is installed. > > -- > Gabriel Genellina This is what I get: 'import site' failed; use -v for traceback ['c:\\temp\\pytest\\Debug\\python25_d.zip', 'C:\\Python25\\Lib', 'C:\ \Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', '', 'c:\\temp\\pytest\ \Debug'] In fact, the 'import site' failed; use -v for traceback happens when I call the Py_Initialize(). As can be seen from the output, the import sys; and print sys.path works. I also added Py_SetProgramName(argv[0]) before calling PyInitialize() but there was no change. Thanks, Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: SystemError: _PyImport_FixupExtension: module _types not loaded
> "works" in the sense that it prints something; but sys.path is incomplete, > it lacks site-packages and others (they are added by site.py). > It appears that you have installed Python on C:\Python25 and you build > your application executable into c:\temp\pytest\Debug - is that true? > Hmmm, you will need a debug build of Python too, python25_d.lib/.dll. > Perhaps at this stage it's easier to use the Release build, because you > already have python25.lib/dll. > > You have to fix the "import site" error. Use the following command on a > console window before launching your executable: > set PYTHONVERBOSE=1 > You'll see a lot of lines showing the initial imports; you should be able > to detect what's the problem at "import site"; usually it's trying to load > a missing DLL. > > -- > Gabriel Genellina Thank you for your quick reply and your interest. I had a debug python25_d.lib/dll which i was even using to step into the code to see why it was failing but it will take me more time to understand the python code. The other interesting thing I discovered when trying to build my debug python dll with vs2005 usig the build8 solution was that I was even getting the exact same error: Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\ctypes\__init__.py", line 6, in import os as _os, sys as _sys File "C:\Python25\lib\os.py", line 690, in import copy_reg as _copy_reg File "C:\Python25\lib\copy_reg.py", line 7, in from types import ClassType as _ClassType File "C:\Python25\lib\types.py", line 93, in import _types SystemError: _PyImport_FixupExtension: module _types not loaded that I was getting when when trying to run the script. I decided at that point to go back to python2.4, actually activestate python2.4 and then add the ctype module. I will update this thread on my success or failure. Thanks, Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: SystemError: _PyImport_FixupExtension: module _types not loaded
After installing activestate python 2.4 and ctypes-1.0.1.win32- py2.4.exe, everything just worked. So, I decided to stay with 2.4 since I don't have time to figure out the problem. Steve -- http://mail.python.org/mailman/listinfo/python-list