[Python-Dev] Importing DLLs on Windows
M.-A. Lemburg
mal@lemburg.com
Thu, 19 Apr 2001 00:51:11 +0200
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/