469,350 Members | 1,830 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,350 developers. It's quick & easy.

How can this script fail?

Hello,

it's still me, being unable to load certain modules (for instance,
odbc) in scripts that run though IDLE. I've now written a self-
containing script that illustrates the whole problem:

----------------------------------
import sys, os

# find odbc module in Python distribution tree:
for root, dirs, files in os.walk(sys.prefix):
for fname in files:
if fname[0:4] == 'odbc':
libdir = root
libname = fname
print "Got file <%sin dir <%s>" % (libname, libdir)

# Now we've probably found an odbc module. Let's see if its containing
dir is in the path:
# (Case shouldn't matter)
for pdir in sys.path:
if pdir.lower() == libdir.lower():
print "Found in path:"
print "<%s>\n<%s>" % (libdir, pdir)

try:
import odbc
except:
print "But I still couldn't load %s:" % libname
raise
----------------------------------
When this script is run, it produces the following output:

----------------------------------
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

************************************************** **************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
************************************************** **************

IDLE 1.2.2
>>================================ RESTART ================================
Got file <odbc.pydin dir <C:\Python25\Lib\site-packages\win32>
Found in path:
<C:\Python25\Lib\site-packages\win32>
<C:\Python25\lib\site-packages\win32>
But I still couldn't load odbc.pyd:

Traceback (most recent call last):
File "D:\Documents and Settings\nxp10225\Desktop\test.py", line 17,
in <module>
import odbc
ImportError: DLL load failed: Das angegebene Modul wurde nicht
gefunden.
>>================================ RESTART ================================
import odbc
--------------------------------------------------
Note that after restarting the shell, I can manually import odbc via
keyboard.

Thanks,
robert
Aug 27 '08 #1
5 1209
On 2008-08-27 12:37, bo*******@googlemail.com wrote:
Hello,

it's still me, being unable to load certain modules (for instance,
odbc) in scripts that run though IDLE. I've now written a self-
containing script that illustrates the whole problem:
I don't think this is related to IDLE or your setup. The odbc
module is very old and unmaintained, so it's possible that Windows
doesn't find some system DLLs needed for it to work.

If you're looking for a reliable Python ODBC interface, I'd suggest
you have a look at our mxODBC:

http://www.egenix.com/products/python/mxODBC/

If you're just using the odbc module as an example, I'd suggest
you try some other extension modules as well, esp. ones which don't
have external dependencies.
----------------------------------
import sys, os

# find odbc module in Python distribution tree:
for root, dirs, files in os.walk(sys.prefix):
for fname in files:
if fname[0:4] == 'odbc':
libdir = root
libname = fname
print "Got file <%sin dir <%s>" % (libname, libdir)

# Now we've probably found an odbc module. Let's see if its containing
dir is in the path:
# (Case shouldn't matter)
for pdir in sys.path:
if pdir.lower() == libdir.lower():
print "Found in path:"
print "<%s>\n<%s>" % (libdir, pdir)

try:
import odbc
except:
print "But I still couldn't load %s:" % libname
raise
----------------------------------
When this script is run, it produces the following output:

----------------------------------
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

************************************************** **************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
************************************************** **************

IDLE 1.2.2
>>>================================ RESTART ================================
Got file <odbc.pydin dir <C:\Python25\Lib\site-packages\win32>
Found in path:
<C:\Python25\Lib\site-packages\win32>
<C:\Python25\lib\site-packages\win32>
This looks strange... the same module in two dirs that only
differ by case ?

Note that the standard location is C:\Python25\Lib\site-packages
(with capital 'L').
But I still couldn't load odbc.pyd:

Traceback (most recent call last):
File "D:\Documents and Settings\nxp10225\Desktop\test.py", line 17,
in <module>
import odbc
ImportError: DLL load failed: Das angegebene Modul wurde nicht
gefunden.
>>>================================ RESTART ================================
import odbc
--------------------------------------------------
Note that after restarting the shell, I can manually import odbc via
keyboard.

Thanks,
robert
--
http://mail.python.org/mailman/listinfo/python-list
--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Aug 27 2008)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
__________________________________________________ ______________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Aug 27 '08 #2
On Aug 27, 1:08*pm, "M.-A. Lemburg" <m...@egenix.comwrote:
I don't think this is related to IDLE or your setup. The odbc
module is very old and unmaintained, so it's possible that Windows
doesn't find some system DLLs needed for it to work.
Please note that
1) I can type "import odbc" directly into the IDLE shell without
getting an error message,
but only BEFORE I've run a script that tries to import odbc.
2) The same script runs fine under PyWin (which I don't like much as
an environment).
If you're looking for a reliable Python ODBC interface, I'd suggest
you have a look at our mxODBC:
Thanks, but I'm working on some kind of guerilla project of which my
employer doesn't know, so they won't spend any money on a commercial
product.

robert
Aug 27 '08 #3
On 27 Aug, 12:15, "boblat...@googlemail.com"
<boblat...@googlemail.comwrote:
On Aug 27, 1:08*pm, "M.-A. Lemburg" <m...@egenix.comwrote:
I don't think this is related to IDLE or your setup. The odbc
module is very old and unmaintained, so it's possible that Windows
doesn't find some system DLLs needed for it to work.

Please note that
1) I can type "import odbc" directly into the IDLE shell without
getting an error message,
but only BEFORE I've run a script that tries to import odbc.
2) The same script runs fine under PyWin (which I don't like much as
an environment).
If you're looking for a reliable Python ODBC interface, I'd suggest
you have a look at our mxODBC:

Thanks, but I'm working on some kind of guerilla project of which my
employer doesn't know, so they won't spend any money on a commercial
product.

robert
Hello,

Your script works fine for me on my machine (Python 2.5.2, IDLE 1.2.2,
WinXP).

The two directories returned in the 'found in path' section are a
result of the .lower() method being called on the directory names in
the if statement.

So it looks to me as if IDLE/Python is not necessarily the problem. I
notice that if I run a script from IDLE using F5 (this is what you're
doing, right?) the directory that contains the script is inserted at
the begining of sys.path. Is there anything unusual in this
directory, particularly objects called 'odbc'?

Cheers,

Kev
Aug 27 '08 #4
Dennis Lee Bieber wrote:
>On 2008-08-27 12:37, bo*******@googlemail.com wrote:
Got file <odbc.pydin dir <C:\Python25\Lib\site-packages\win32>
Found in path:
<C:\Python25\Lib\site-packages\win32>
<C:\Python25\lib\site-packages\win32>

This looks strange... the same module in two dirs that only
differ by case ?
Even stranger when you take into account that under Windows, path
names are case-preserving/case-ignored -- so Lib and lib are the SAME
directory (I suspect some environment variable has the directory listed
twice with the change in spelling -- PythonPath perhaps?)
Please note that one of the lines is the directory that was found in the
"os.walk" loop and the other is the one in sys.path -- I just had them
printed out on adjacent lines to point out the difference in case.

Anyway, the thing was fixed when I put C:\Python25 into the DOS $PATH
environment variable. Still strange though.

robert
Aug 27 '08 #5
On 2008-08-27 13:15, bo*******@googlemail.com wrote:
On Aug 27, 1:08 pm, "M.-A. Lemburg" <m...@egenix.comwrote:
>I don't think this is related to IDLE or your setup. The odbc
module is very old and unmaintained, so it's possible that Windows
doesn't find some system DLLs needed for it to work.

Please note that
1) I can type "import odbc" directly into the IDLE shell without
getting an error message,
but only BEFORE I've run a script that tries to import odbc.
It is possible that the script import of the odbc module left
an uninitialized or half-initialized module object in sys.modules.

Another possibility is that IDLE and the script import different
modules with the same name due to problems on your sys.path (see
my first reply).
2) The same script runs fine under PyWin (which I don't like much as
an environment).
--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Aug 27 2008)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
__________________________________________________ ______________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Aug 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.