Help: Runtime Error when loading ".pyd" module

2006-03-01 Thread Terry Tang
Hi There,

We are extending Python interpreter to support  special functions of our
tools. What we did is to compile Python's source code (which is got from the
an installation on a Linux environment for Python 2.3.3) and our extensions
(C++ code) on Windows with Microsoft Visual C++ 6.0 compiler to generate the
extended Python interpreter.

It works well on Linux and for the basic Python modules and our special
modules on Windows. But whenever a ".pyd" module is loaded by a statement
like the following:
import socket; # which finally calls:  import _socket
or
import Tkinter; # which finally calls: import _tkinter
or
import datetime
it hits a "Runtime Error" (which is shown in a message box saying "abnormal
program termination") and a message like the following is printed in the
console:
Fatal Python error: Interpreter not initialized (version mismatch?)


I tried to use Microsoft Visual Studio to debug the program and set a
breakpoint at "Py_FatalError()", but the breakpoint is not hit. I also
traced the loading process of the ".pyd" file in function
"_PyImport_LoadDynamicModule()": the ".pyd" file is correctly located and
loaded, and its "init" function seems be got correctly, but when the
initialization function is called, the above error happens.

I am pretty sure that Python is initialized by "Py_Initialize()", and the
".pyd" files are from the standard Python installation with the same version
(2.3.3).

Does anyone have any idea about the crash? Does the initialization function
from a ".pyd" file require special environment?

Because the ".pyd" files (like "_socket.pyd", _tkinter.pyd" and
"datetime.pyd" etc) are precompiled and contained in the Python installer
for Windows, I don't know how to manually compile them and debug them.

I appreciate your help in advance.

-Terry


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Runtime Error when loading ".pyd" module

2006-03-06 Thread Terry Tang
Fredrik,

Thanks, the information is very helpful, and I have resolved our problem. I
was not aware that the .pyd files will load pythonNN.dll.

Regards.

-Terry


- Original Message - 
From: "Fredrik Lundh" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, March 02, 2006 12:53 AM
Subject: Re: Runtime Error when loading ".pyd" module


> Terry Tang wrote:
>
> > it hits a "Runtime Error" (which is shown in a message box saying
"abnormal
> > program termination") and a message like the following is printed in the
> > console:
> > Fatal Python error: Interpreter not initialized (version mismatch?)
>
> both the main executable (e.g. python.exe or your own application)
> and the various PYD files are linked against the Python core DLL (e.g.
> python24.dll), and this error typically indicates that the PYD picks up
> another copy of that DLL than the EXE is using.
>
> e.g.
>
> 1. python.exe starts
> 2. when python.exe needs python24.dll, the runtime linker finds
> /foo/bar/python24.dll and loads it
> 3. python.exe initializes the python24.dll instance
> 4. python.exe starts your python program
> 5. your python program imports the foobar module
> 6. python.exe loads /foo/modules/foobar.pyd for you
> 7. when foobar.pyd needs python24.dll, the runtime linker finds
> /flub/python24.dll before /foo/bar/python24.dll
> 8. foobar.pyd calls /flub/python24.dll, which notices that it hasn't
> been properly initialized, and terminates.
>
> another possible option is that foobar.pyd is from an earlier python
> version, so you get
>
> 7. when foobar.pyd needs python23.dll, the runtime linker finds
> /foo/bar/python23.dll and loads it
> 8. foobar.pyd calls /foo/bar/python23.dll, which notices that it
> hasn't been properly initialized, and terminates.
>
> but the PYD loader used in step 6 has extra logic in it to attempt
> to detect this case (it checks what python DLLs a PYD file is using
> before it loads the PYD), so you usually get a better error message
> if this is the case.
>
> anyway, the first thing to do is to look for stray pythonXX.dll files
> ("python23.dll" in your case).
>
> hope this helps!
>
> 
>
>
>
>
>

-- 
http://mail.python.org/mailman/listinfo/python-list