py2exe odbc:cannot import dbi module

M

Marc Ederis

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
 
T

Thomas Heller

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
 
T

Thomas Heller

Thomas Heller said:
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
 
M

Marc Ederis

Great, it works, thanks Thomas!

But why did you say that odbc32.dll shouldn't be distributed? Because
our distribution should only contain python specific files?
If that's the reason, then I should probably take out MFC42.dll too,
right? Well, I'll just take them out and test... I guess I should
really familiarize myself with distutils, so I understand more about
all this!

-Marc
 
T

Thomas Heller

Great, it works, thanks Thomas!

But why did you say that odbc32.dll shouldn't be distributed? Because
our distribution should only contain python specific files?
If that's the reason, then I should probably take out MFC42.dll too,
right? Well, I'll just take them out and test... I guess I should
really familiarize myself with distutils, so I understand more about
all this!

This has nothing to do with distutils.

There are legal reasons (but IANAL), you must check for each file if you
are allowed to redistribute it.

Second, there are technical reasons. I'm not sure if you distribute
odbc32.dll whether the resulting executable would work on a machine
where no odbc is installed or not, but I guess there are more files
needed. For Windows, you probably need to download something called
'Microsoft data access components', follow their installation
guidelines, and make sure that you read their license (or not ;-)

py2exe can only make an educated guess whether the files it collects are
'system files' which must not be redistributed or not, which fails in
this case for odbc32.dll.

Thomas
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top