Python or Windows seems to have trouble importing DLLs when inside packages. I'm working on an extension which pulls in a DLL gmp31.dll which lives inside a package dir mx/Number/mxNumber along side the Python wrapper extension mxNumber.pyd. Currently, I'm using this code in the subpackage's __init__.py: # On Windows we also distribute the GMP DLL (in the win32 subdir). To # have Win32 find the DLL we need to be explicit about the path in # sys.path though. This trick works for all startup directories # *except* \PythonXX (for some reason this fails), but is not thread # safe... import sys, os if sys.platform[:3] == 'win': abspath = os.path.abspath(__path__[0]) sys.path.insert(0, abspath) from mxNumber import * sys.path.remove(abspath) else: from mxNumber import * I don't have any clue why the import works from everywhere *except* the Python21 install directory... anyone does ? Thanks, -- Marc-Andre Lemburg ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Pages: http://www.lemburg.com/python/
Sorry for the delay -- I had a hard time understanding what this writeup meant, so had to download the package and try it. [M.-A. Lemburg]
Python or Windows seems to have trouble importing DLLs when inside packages. I'm working on an extension which pulls in a DLL gmp31.dll which lives inside a package dir mx/Number/mxNumber along side the Python wrapper extension mxNumber.pyd.
Concretely, I have these files now, under my Python 2.1 installation directory: C:\Python21>dir/b/on mx\Number\mxNumber gmp31.dll mxNumber.pyd mxNumber.h test.py __init__.py C:\Python21>
Currently, I'm using this code in the subpackage's __init__.py:
And by "the subpackage" here I believe you mean the tail-end mxNumber directory, previously called "a package". IOW, you're talking specifically about \Python21\mx\Number\mxNumber\__init__.py If you meant something else, scream.
# On Windows we also distribute the GMP DLL (in the win32 subdir). To # have Win32 find the DLL we need to be explicit about the path in # sys.path though. This trick works for all startup directories # *except* \PythonXX (for some reason this fails), but is not thread # safe... import sys, os if sys.platform[:3] == 'win': abspath = os.path.abspath(__path__[0]) sys.path.insert(0, abspath) from mxNumber import * sys.path.remove(abspath)
else: from mxNumber import *
I don't have any clue why the import works
Which import are you talking about? Please show exactly what you do that fails -- I haven't been able to find any problem here. For example, I replaced \Python21\mx\Number\mxNumber\__init__.py which contains the code you showed above, with this two-liner: from mxNumber import * from mxNumber import __version__ Having done that, here's a shell session started in the installation directory, and after a reboot "just to make sure": C:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
from mx.Number import * Integer(928349238479328749L)**2 861832308585149602001042573617905001
So nothing failed. What do *you* do that fails? Here's another session started from a "random" directory: C:\Code>\python21\python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
from mx.Number import * Integer(92387498327493243879L)**2 8535449847212566935021074270390170966641
Same thing.
from everywhere *except* the Python21 install directory...
It would more helpful to name a specific directory than to make an untrue
claim
Tim Peters wrote:
Sorry for the delay -- I had a hard time understanding what this writeup meant, so had to download the package and try it.
Oh, sorry that I wasn't clear enough. Referring to the mxNumber package, I am seeing this situation: # This works... (note the start directory) C:\WINDOWS>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
# This doesn't.... (from the Python install directory) D:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number Traceback (most recent call last): File "<stdin>", line 1, in ? File "d:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "d:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "d:\python21\mx\Number\mxNumber\__init__.py", line 21, in ? from mxNumber import * ImportError: DLL load failed: Ein der fnr die Ausfnhrung dieser Anwendung notwen dige Bibliothekdateien kann nicht gefunden werden.
# OTOH, this works.... (one level below the Python install directory) D:\Python21>cd mx D:\Python21\mx>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number
[M.-A. Lemburg]
Python or Windows seems to have trouble importing DLLs when inside packages. I'm working on an extension which pulls in a DLL gmp31.dll which lives inside a package dir mx/Number/mxNumber along side the Python wrapper extension mxNumber.pyd.
Concretely, I have these files now, under my Python 2.1 installation directory:
C:\Python21>dir/b/on mx\Number\mxNumber gmp31.dll mxNumber.pyd mxNumber.h test.py __init__.py
C:\Python21>
Currently, I'm using this code in the subpackage's __init__.py:
And by "the subpackage" here I believe you mean the tail-end mxNumber directory, previously called "a package". IOW, you're talking specifically about
\Python21\mx\Number\mxNumber\__init__.py
Right.
If you meant something else, scream.
# On Windows we also distribute the GMP DLL (in the win32 subdir). To # have Win32 find the DLL we need to be explicit about the path in # sys.path though. This trick works for all startup directories # *except* \PythonXX (for some reason this fails), but is not thread # safe... import sys, os if sys.platform[:3] == 'win': abspath = os.path.abspath(__path__[0]) sys.path.insert(0, abspath) from mxNumber import * sys.path.remove(abspath)
else: from mxNumber import *
I don't have any clue why the import works
Which import are you talking about? Please show exactly what you do that fails -- I haven't been able to find any problem here. For example, I replaced
\Python21\mx\Number\mxNumber\__init__.py
which contains the code you showed above, with this two-liner:
from mxNumber import * from mxNumber import __version__
Having done that, here's a shell session started in the installation directory, and after a reboot "just to make sure":
C:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
from mx.Number import * Integer(928349238479328749L)**2 861832308585149602001042573617905001
So nothing failed.
Hmm, you are right, it does work for me too (I wonder why I thought it failed without the sys.path tweaking... probably just tested from the Python install dir): C:\WINDOWS>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
C:\WINDOWS>d:
D:\Python21\mx>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
D:\Python21\mx>cd ..
D:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number Traceback (most recent call last): File "<stdin>", line 1, in ? File "d:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "d:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "d:\python21\mx\Number\mxNumber\__init__.py", line 11, in ? from mxNumber import * ImportError: DLL load failed: Ein der fnr die Ausfnhrung dieser Anwendung notwen dige Bibliothekdateien kann nicht gefunden werden.
What do *you* do that fails? Here's another session started from a "random" directory:
C:\Code>\python21\python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
from mx.Number import * Integer(92387498327493243879L)**2 8535449847212566935021074270390170966641
Same thing.
from everywhere *except* the Python21 install directory...
It would more helpful to name a specific directory than to make an untrue claim
.
Ok, ok ;-) Please try starting Python from your Python install dir and then do the import. BTW, I'm doing this on Windows 95 in case this matters (which I'm sure it does :-/).
BTW, it's a mondo cool package! I had a lot of fun with it.
Thanks :)
But then I was able to, since I stopped trying to guess what your problem was <wink>. What's up? I was running Win98SE in the above, but that shouldn't make a difference. Perhaps, during development, you left crap sitting around in your installation directory that's confusing your attempts to import things? If not, please be very explicit about what you do that fails, and what "fails" means (crash, ImportError, Windows error box, ...?).
"fail" means that Python cannot find the gmp31.dll sitting right next to the mxNumber.pyd in the same directory. This should normally work, but somehow doesn't when Python is started from the install dir:
import mx.Number import mx # directory mx # trying mx\__init__.pyd # trying mx\__init__.dll # trying mx\__init__.py # mx\__init__.pyc matches mx\__init__.py import mx # precompiled from mx\__init__.pyc import mx.Number # directory mx\Number # trying mx\Number\__init__.pyd # trying mx\Number\__init__.dll # trying mx\Number\__init__.py # mx\Number\__init__.pyc matches mx\Number\__init__.py import mx.Number # precompiled from mx\Number\__init__.pyc # trying mx\Number\Number.pyd # trying mx\Number\Number.dll # trying mx\Number\Number.py # mx\Number\Number.pyc matches mx\Number\Number.py import mx.Number.Number # precompiled from mx\Number\Number.pyc import mx.Number.mxNumber # directory mx\Number\mxNumber # trying mx\Number\mxNumber\__init__.pyd # trying mx\Number\mxNumber\__init__.dll # trying mx\Number\mxNumber\__init__.py # mx\Number\mxNumber\__init__.pyc matches mx\Number\mxNumber\__init__.py import mx.Number.mxNumber # precompiled from mx\Number\mxNumber\__init__.pyc # trying mx\Number\mxNumber\mxNumber.pyd Traceback (most recent call last): File "<stdin>", line 1, in ? File "d:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "d:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "d:\python21\mx\Number\mxNumber\__init__.py", line 11, in ? from mxNumber import * ImportError: DLL load failed: Ein der fnr die Ausfnhrung dieser Anwendung notwen dige Bibliothekdateien kann nicht gefunden werden.
[MAL]
Oh, sorry that I wasn't clear enough.
Me neither (see below).
Referring to the mxNumber package, I am seeing this situation:
# This works... (note the start directory)
C:\WINDOWS>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
# This doesn't.... (from the Python install directory)
D:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number Traceback (most recent call last): File "<stdin>", line 1, in ? File "d:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "d:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "d:\python21\mx\Number\mxNumber\__init__.py", line 21, in ? from mxNumber import * ImportError: DLL load failed: Ein der fnr die Ausfnhrung dieser Anwendung notwen dige Bibliothekdateien kann nicht gefunden werden.
Well, there's your problem: looks some German hackers got into your machine and screwed up the OS <wink>. Now let me clarify what I wrote before: when I said I couldn't provoke a problem, I meant ANY problem. It didn't matter whether I used the __init__.py you shipped, or used the two-liner I posted, and it didn't matter whether I started Python 2.1 from the install directory or from C:\Code (etc). Nothing failed no matter what I tried. The only thing I see different in what you did above is that your Python install directory is on a different drive (D: instead of C:). I only have one drive here, so I can't do a good job of simulating that. Best I can do here is fake it via the DOS subst command: K:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number from mx.Number import *
Still no problem. What happens if you install Python onto your C: drive instead? And if that does work for you, is it because of the C: drive, or because you left some old development work on your D: drive that's confusing things? Do you have confirmation of your problem from anyone else? Or are you the only one who has bumped into it?
... Please try starting Python from your Python install dir and then do the import.
I already had, in the last msg. And again above.
BTW, I'm doing this on Windows 95 in case this matters (which I'm sure it does :-/).
Possibly, but can't say. We need more data. BTW, do you understand what your code does <0.7 wink>? That is, there are packages, modules *and* DLLs with the same base name, and "import *" everywhere. I've always stayed so far away from import end cases that I have no idea what the rules are supposed to be when you live on the edge. That may have something to do with this too, although I can't see how (although since I don't know what the rules are, that's a guess too!).
Tim Peters wrote:
[MAL]
Oh, sorry that I wasn't clear enough.
Me neither (see below).
Referring to the mxNumber package, I am seeing this situation:
# This works... (note the start directory)
C:\WINDOWS>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
# This doesn't.... (from the Python install directory)
D:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number Traceback (most recent call last): File "<stdin>", line 1, in ? File "d:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "d:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "d:\python21\mx\Number\mxNumber\__init__.py", line 21, in ? from mxNumber import * ImportError: DLL load failed: Ein der fnr die Ausfnhrung dieser Anwendung notwen dige Bibliothekdateien kann nicht gefunden werden.
Well, there's your problem: looks some German hackers got into your machine and screwed up the OS <wink>.
Could be...
Now let me clarify what I wrote before: when I said I couldn't provoke a problem, I meant ANY problem. It didn't matter whether I used the __init__.py you shipped, or used the two-liner I posted, and it didn't matter whether I started Python 2.1 from the install directory or from C:\Code (etc). Nothing failed no matter what I tried.
OK. I tried the same on a Win98 box with a fresh Python and mxNumber install -- and found no problems either; which leaves me rather clueless about where the failures on my Win95 box originate. Could someone else with a Win95 box perhaps test this ? Thanks anyway for hanging on, -- Marc-Andre Lemburg ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Pages: http://www.lemburg.com/python/
I see the same Behaviour as Marc-Andre: Traceback in Win95 (running under VMWare, running under Win2k). C:\WINDOWS>\python21\python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
quit 'Use Ctrl-Z plus Return to exit.'
C:\WINDOWS>cd \python21
C:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number Traceback (most recent call last): File "<stdin>", line 1, in ? File "c:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "c:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "c:\python21\mx\Number\mxNumber\__init__.py", line 21, in ? from mxNumber import * ImportError: DLL load failed: One of the library files needed to run this applic ation cannot be found.
C:\Python21>ver
Windows 95. [Version 4.00.950] C:\Python21> Marc-Andre, what about other python versions? Thomas
Thomas Heller wrote:
I see the same Behaviour as Marc-Andre: Traceback in Win95 (running under VMWare, running under Win2k).
C:\WINDOWS>\python21\python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number print mx.Number.Float(3.141) 3.14100000000000001421e+0
quit 'Use Ctrl-Z plus Return to exit.'
C:\WINDOWS>cd \python21
C:\Python21>python Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.
import mx.Number Traceback (most recent call last): File "<stdin>", line 1, in ? File "c:\python21\mx\Number\__init__.py", line 9, in ? from Number import * File "c:\python21\mx\Number\Number.py", line 11, in ? from mxNumber import * File "c:\python21\mx\Number\mxNumber\__init__.py", line 21, in ? from mxNumber import * ImportError: DLL load failed: One of the library files needed to run this applic ation cannot be found.
C:\Python21>ver
Windows 95. [Version 4.00.950]
C:\Python21>
Marc-Andre, what about other python versions?
mxNumber needs Python 2.1, so I have no way of testing it under Python 2.0. Both imports work on Winows 98SE, so I guess this has something to do with Win95 no handling imports using relative paths correctly (if you run Python with -vv you'll see that Python searches using relative paths when started from C:\Python21). -- Marc-Andre Lemburg ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Pages: http://www.lemburg.com/python/
participants (3)
-
M.-A. Lemburg
-
Thomas Heller
-
Tim Peters