473,558 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SystemError: _PyImport_Fixup Extension: 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 "<string>", line 1, in <module>
File "C:\Python25\li b\ctypes\__init __.py", line 6, in <module>
import os as _os, sys as _sys
File "C:\Python25\li b\os.py", line 690, in <module>
import copy_reg as _copy_reg
File "C:\Python25\li b\copy_reg.py", line 7, in <module>
from types import ClassType as _ClassType
File "C:\Python25\li b\types.py", line 93, in <module>
import _types
SystemError: _PyImport_Fixup Extension: 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_SimpleStr ing("import ctypes");
Py_Finalize();
return 0;
}

Steve

Feb 12 '07 #1
6 2342
En Mon, 12 Feb 2007 15:44:36 -0300, <us*****@ingfam ily.netescribió :
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_SimpleStr ing("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_SetProgramNa me (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

Feb 12 '07 #2
On Feb 12, 2:25 pm, "Gabriel Genellina" <gagsl...@yahoo .com.arwrote:
En Mon, 12 Feb 2007 15:44:36 -0300, <usen...@ingfam ily.netescribió :
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_SimpleStr ing("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_SetProgramNa me (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\\pyte st\\Debug\\pyth on25_d.zip', 'C:\\Python25\\ Lib', 'C:\
\Python25\\DLLs ', 'C:\\Python25\\ Lib\\lib-tk', '', 'c:\\temp\\pyte st\
\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_SetProgramNa me(argv[0]) before calling
PyInitialize() but there was no change.

Thanks,
Steve

Feb 15 '07 #3
En Thu, 15 Feb 2007 15:42:51 -0300, <us*****@ingfam ily.netescribió :
This is what I get:

'import site' failed; use -v for traceback
['c:\\temp\\pyte st\\Debug\\pyth on25_d.zip', 'C:\\Python25\\ Lib', 'C:\
\Python25\\DLLs ', 'C:\\Python25\\ Lib\\lib-tk', '', 'c:\\temp\\pyte st\
\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_SetProgramNa me(argv[0]) before calling
PyInitialize() but there was no change.
"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

Feb 15 '07 #4
"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 "<string>", line 1, in <module>
File "C:\Python25\li b\ctypes\__init __.py", line 6, in <module>
import os as _os, sys as _sys
File "C:\Python25\li b\os.py", line 690, in <module>
import copy_reg as _copy_reg
File "C:\Python25\li b\copy_reg.py", line 7, in <module>
from types import ClassType as _ClassType
File "C:\Python25\li b\types.py", line 93, in <module>
import _types
SystemError: _PyImport_Fixup Extension: 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

Feb 15 '07 #5
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

Feb 16 '07 #6
En Thu, 15 Feb 2007 21:49:56 -0300, <us*****@ingfam ily.netescribió :
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.
Glad to see it worked, at least on 2.4

--
Gabriel Genellina

Feb 16 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3052
by: Gerrit Holl | last post by:
Hi, I found a cool way to trigger a SystemError: >>> exec CodeType(0,0,0,0,"",(),(),(),"","",0,"") XXX lineno: 0, opcode: 0 Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.2/site-packages/", line 0, in File "/usr/lib/python2.2/site-packages/", line 0, in
8
3936
by: Irmen de Jong | last post by:
What would be the best way, if any, to obtain the bytecode for a given loaded module? I can get the source: import inspect import os src = inspect.getsource(os) but there is no ispect.getbytecode() ;-)
1
6685
by: ulf | last post by:
Hello, After I got a FileNotFoundException in my real life CSharp code, I nailed it down to the following line: System.EnterpriseServices.ResourcePool rp = new System.EnterpriseServices.ResourcePool(null); The exception I get for this line is System.IO.FileNotFoundException: The specified module could not be found.
2
2646
by: robert | last post by:
From the trace of a 2.3.5 software i got: \'SystemError: C:\\\\sf\\\\python\\\\dist23\\\\src\\\\Objects\\\\cellobject.c:22: bad argument to internal function\\n\'] from the middle of normal function / or its call. What is this?
9
1221
by: noamsml | last post by:
Hi, I am new to python and am currently writing my first application. One of the problems I quickly ran into, however, is that python's imports are very different from php/C++ includes in the sense that they completely wrap the imported script in a module object. One of the problems with this was that a plugin system that I am making...
3
10059
by: geevaa | last post by:
Hi group, PHP Warning: Module 'readline' already loaded in Unknown on line 0 what this warning means? please help me by explaining
4
1650
by: Peter J. Bismuti | last post by:
I'm having trouble understanding how namespaces work in modules. I want to execute a module within the interpreter and then have values that are calculated persist so that other modules that get executed can retrieve them. For example, consider the two simple modules below. The first method fails and I'm not sure exactly why. (Note: ...
0
1829
by: Matt Nordhoff | last post by:
Barak, Ron wrote: For some reason, when you run "import locale", it's importing wx.locale instead of the "locale" module from the stdlib. However, I have no idea why that would be happening... Did you do something to add wx to your PYTHONPATH? Maybe do "import sys; print sys.path" or "import os; print os.environ" to verify this. ...
20
5761
by: Nates | last post by:
I have a .bas file saved locally that I load into my Acces project to run a particular sub. I use the following code to load the module (which works fine): I use the following loop to remove the module: The above works fine (both adding the module and subsequantly removing it) provided I do not run any code within the module once it...
0
7629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7836
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8061
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5455
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.