Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

py2app chokes on MySQLdb

Question posted by: AdamGr (Newbie) on June 27th, 2008 06:08 PM
I am currently trying to convert a program I just wrote to application form, on the Mac. I'm using py2app to accomplish this, and everything works fine up until the last stage; when I try to complete the conversion with:
Code: ( text )
  1. python setup.py py2app

and then run the resulting executable, I get the error:
Code: ( text )
  1. ImportError: No module named MySQLdb

The really strange thing is that when I was testing the application creation by making an app bundle, using
Code: ( text )
  1. python setup.py py2app -A

the resulting application bundle worked perfectly. So something is going wrong between making the app bundle and creating the actual app itself. The entire purpose of my program is database connection, so commenting out that portion of its capabilities is not an option.

Thanks ahead of time,
Adam
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
jlm699's Avatar
jlm699
Needs Regular Fix
313 Posts
June 27th, 2008
06:27 PM
#2

Re: py2app chokes on MySQLdb
I've had similar problems when building executables for Windows and Linux machines. Within your setup.py script you'll need to package up the MySQL module so that it gets distributed along with the rest of your source code.

Try googling py2app with the MySQL module to see if results come up, as different packages require different steps to get them to play nice with py2exe (in my case). Here's an example of my setup.py script for making matplotlib distributable:

Code: ( text )
  1. #!/usr/bin/python
  2.  
  3. import sys
  4.  
  5. try:
  6.     # if this doesn't work, try import modulefinder
  7.     import py2exe.mf as modulefinder
  8.     import win32com
  9.     for p in win32com.__path__[1:]:
  10.         modulefinder.AddPackagePath("win32com", p)
  11.     for extra in ["win32com.shell"]: #,"win32com.mapi"
  12.         __import__(extra)
  13.         m = sys.modules[extra]
  14.         for p in m.__path__[1:]:
  15.             modulefinder.AddPackagePath(extra, p)
  16. except ImportError:
  17.     # no build path setup, no worries.
  18.     pass
  19.  
  20. from distutils.core import setup
  21. from distutils.filelist import findall
  22. import matplotlib
  23. import py2exe
  24. import os
  25.  
  26. manifest = """[redacted for length]"""
  27.  
  28. mpdatadir = matplotlib.get_data_path()
  29. mpdata = findall(mpdatadir)
  30. dataFiles = []
  31. for f in mpdata:
  32.     dir = os.path.join('matplotlibdata', f[len(mpdatadir)+1:])
  33.     dataFiles.append((os.path.split(dir)[0], [f]))
  34.  
  35. setup(
  36.     zipfile = None,
  37.     # We use os.path.join for portability
  38.     package_dir = {'': os.path.join('..', 'Common')},
  39.     py_modules = [ """[redacted, my own modules]""" ],
  40.     options={
  41.         'py2exe': {
  42.             'packages' :    ['matplotlib.numerix', 'pytz',
  43.                             'matplotlib.backends.backend_tkagg'],
  44.             'includes':  'matplotlib.numerix.random_array',
  45.             'excludes':  ['_gtkagg', '_tkagg'],
  46.             'dll_excludes':['libgdk-win32-2.0-0.dll',
  47.                             'libgobject-2.0-0.dll',
  48.                             'MSVCP80.dll',
  49.                             'MSVCR80.dll']
  50.         }
  51.     },
  52.     data_files = dataFiles,
  53.     windows = [
  54.         {
  55.             "script": "[redacted]",
  56.             "icon_resources": [(1, "iconJ.ico")],
  57.             "other_resources": [(24,1,manifest)]
  58.         }
  59.     ],
  60. )

I had to do this different ways for different modules.
Some simply needed to be imported into the setup.py script.
Some needed to use the modulefinder in the beginning (but only matplotlib that I found)
Others simply needed to be included in the packages or includes lists that are part of the py2exe dictionary. I would try doing the import method first, then the packages/includes list entries. But of course that's if a quick google doesn't turn anything up!

As a last resort there may be some similar modulefinder (py2exe.mf) within py2app that you could try out

Reply
AdamGr's Avatar
AdamGr
Newbie
6 Posts
June 29th, 2008
04:43 AM
#3

Re: py2app chokes on MySQLdb
oy, ok thanks. I just discovered some major bugs in my code, so I'm gonna hold off on converting it for a little while.

Reply
Reply
Not the answer you were looking for? Post your question . . .
182,318 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Python Forum Contributors