Runtime error importing extension modules

David Bolen db3l at fitlinxx.com
Mon Oct 2 21:53:37 EDT 2000


lss at excosoft.se writes:

> I have a problem with PYDs in an application using Python as an
> embedded scripting language. In this case, the application and Python
> are statically linked together into a single executable. To get this to
> work, I had to remove definitions of USE_DL_EXPORT and USE_DL_IMPORT
> and other DLL-related preprocessor macros. Now, however, each attempt
> to import a PYD results in a runtime error. Does anyone have any
> pointers on how I may link Python together statically with a C++
> application and yet retain the the ability to import dynamic extension
> modules? Is USE_DL_IMPORT or USE_DL_EXPORT necessary for this, and if
> so, how can I have them without compromising the ability to link Python
> statically?

I'm not sure you'll be able to mix the two.  The dynamic extensions
are specifically linked against the dynamic Python core, so if you try
to import them the extension is going to find it is talking to an
uninitialized core, since its your static version that is actually
performing the import.  This is actually the same problem state that
is being seen if you import a Python 1.5.2 extension under a Python
1.6/2.0 script under Windows, for example.

So you either need to make your program use the DLL version of Python
(is there a specific reason you can't do this?), or you need to
rebuild the extensions and link them into your application statically
as well (this is similar to the freeze process).

I suppose you could experiment with having your application not only
link Python statically for its own purpose, but also initialize a
dynamically linked interpreter for use with the imports, but I don't
know if that could prove workable.  You'd still be unable to execute
scripts that tried to cross the boundary.  Not sure what sorts of
naming collisions you might run into in that case as well.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list