468,104 Members | 1,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

py2exe odbc:cannot import dbi module

Hello,

I'm trying to create an executable with py2exe, and it uses the odbc
module. The script runs fine until I use py2exe on it and run the
..exe. Then I get:

--
Traceback (most recent call last):
File "dbmod.py", line 2, in ?
File "odbc.pyo", line 9, in ?
File "odbc.pyo", line 7, in __load
odbc: Cannot import dbi module
--

dbi.dll is in the dist folder, and so is odbc.pyd.

Does anyone know how to solve this problem?

Thanks,
-Marc
Jul 18 '05 #1
2 3186
me*****@hotmail.com (Marc Ederis) writes:
Hello,

I'm trying to create an executable with py2exe, and it uses the odbc
module. The script runs fine until I use py2exe on it and run the
.exe. Then I get:

--
Traceback (most recent call last):
File "dbmod.py", line 2, in ?
File "odbc.pyo", line 9, in ?
File "odbc.pyo", line 7, in __load
odbc: Cannot import dbi module
--

dbi.dll is in the dist folder, and so is odbc.pyd.

Does anyone know how to solve this problem?


It seems you have to first explicitely import the dbi module before the
odbc module can be imported.

"""
import dbi, odbc
"""

py2exe doesn't know that dbi.dll is a python extension - it is only
found as binary dependency. And you should not (must not?) distribute
odbc32.dll, which is also copied to the dist folder.

In py2exe 0.5, you *should* be able to specify
dll_exludes = ["odbc32.dll"]
but this doesn't seem to work.

Thomas
Jul 18 '05 #2
Thomas Heller <th*****@python.net> writes:
me*****@hotmail.com (Marc Ederis) writes:
Hello,

I'm trying to create an executable with py2exe, and it uses the odbc
module. The script runs fine until I use py2exe on it and run the
.exe. Then I get:

--
Traceback (most recent call last):
File "dbmod.py", line 2, in ?
File "odbc.pyo", line 9, in ?
File "odbc.pyo", line 7, in __load
odbc: Cannot import dbi module
--

dbi.dll is in the dist folder, and so is odbc.pyd.

Does anyone know how to solve this problem?
It seems you have to first explicitely import the dbi module before the
odbc module can be imported.

"""
import dbi, odbc
"""

py2exe doesn't know that dbi.dll is a python extension - it is only
found as binary dependency.


You can avoid the need for 'import dbi' by patching the builtin
hidden_imports dictionary, in the get_hidden_imports() method in
py2exe\build_exe.py, near line 650. Add
"odbc": ["dbi"]
and it should work.
And you should not (must not?) distribute
odbc32.dll, which is also copied to the dist folder.

In py2exe 0.5, you *should* be able to specify
dll_exludes = ["odbc32.dll"]
but this doesn't seem to work.


I got this wrong - it does work, but you have to pass an options dict to
the setup script, something like this:

setup(...
options = {"py2exe":
{"dll_excludes": ["odbc32.dll"]}}
)

Thomas
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by dananrg | last post: by
reply views Thread by jantod | last post: by
1 post views Thread by Daniel Mark | last post: by
2 posts views Thread by Sean Davis | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.