[Python.NET] import works only after failed import

Leonard :paniq: Ritter paniq at gmx.net
Wed Jan 14 13:10:58 EST 2004


this is even funnier. importing a .net assembly seems only to work if the dll has been loaded before.

in each try, i restart python from the directory where the .net DLL is located.

first try:

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import CLR.QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named QuenceNET

second try:

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import CLR
>>> import CLR.QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named QuenceNET
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
>>> dir(CLR.QuenceNET)
['__doc__', '__name__']

third try (optimized):

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import CLR
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
>>> dir(CLR.QuenceNET)
['__doc__', '__name__']

fourth try (variant):

O:\Quence\debug>python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named QuenceNET
>>> import QuenceNET
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initQuenceNET)
>>> import CLR.QuenceNET
>>> dir(CLR.QuenceNET)
['__doc__', '__name__']

so to import my custom assembly in python, the code currently looks like this:

import CLR
try:
        import QuenceNET # for the error
except:
        pass # catch
import CLR.QuenceNET


-- Leonard Ritter
-- paniq at gmx.net
-- http://www.quence.com
-- http://www.paniq.de





More information about the PythonDotNet mailing list