How can this script fail?

B

boblatest

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 <%s> in 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.2Got file <odbc.pyd> in 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.--------------------------------------------------
Note that after restarting the shell, I can manually import odbc via
keyboard.

Thanks,
robert
 
M

M.-A. Lemburg

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 <%s> in 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.2Got file <odbc.pyd> in 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.
--------------------------------------------------
Note that after restarting the shell, I can manually import odbc via
keyboard.

Thanks,
robert

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Aug 27 2008)________________________________________________________________________

:::: 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
 
B

boblatest

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
 
K

kdwyer

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).


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
 
R

Robert Latest

Dennis said:
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
 
M

M.-A. Lemburg

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)________________________________________________________________________

:::: 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top