473,382 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1347
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
5
by: Shawn Modersohn | last post by:
For the script: <script language="JavaScript"> function pullPage(){ var arrayLength=document.teamSelectionF.teamSelectionS.length; var pageNav = new Array(arrayLength); var...
2
by: John | last post by:
The following code works OK in IE 6.0 but does not work in Netscape 7. The image does not shift when one scrolls down but stays stationary in Netscape. Please help Thank you John function...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
4
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.