py2app chokes on MySQLdb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdamGr
    New Member
    • Jun 2008
    • 6

    py2app chokes on MySQLdb

    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:
     python setup.py py2app
    and then run the resulting executable, I get the error:
    Code:
     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:
     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
  • jlm699
    Contributor
    • Jul 2007
    • 314

    #2
    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=python]
    #!/usr/bin/python

    import sys

    try:
    # if this doesn't work, try import modulefinder
    import py2exe.mf as modulefinder
    import win32com
    for p in win32com.__path __[1:]:
    modulefinder.Ad dPackagePath("w in32com", p)
    for extra in ["win32com.shell "]: #,"win32com.map i"
    __import__(extr a)
    m = sys.modules[extra]
    for p in m.__path__[1:]:
    modulefinder.Ad dPackagePath(ex tra, p)
    except ImportError:
    # no build path setup, no worries.
    pass

    from distutils.core import setup
    from distutils.filel ist import findall
    import matplotlib
    import py2exe
    import os

    manifest = """[redacted for length]"""

    mpdatadir = matplotlib.get_ data_path()
    mpdata = findall(mpdatad ir)
    dataFiles = []
    for f in mpdata:
    dir = os.path.join('m atplotlibdata', f[len(mpdatadir)+ 1:])
    dataFiles.appen d((os.path.spli t(dir)[0], [f]))

    setup(
    zipfile = None,
    # We use os.path.join for portability
    package_dir = {'': os.path.join('. .', 'Common')},
    py_modules = [ """[redacted, my own modules]""" ],
    options={
    'py2exe': {
    'packages' : ['matplotlib.num erix', 'pytz',
    'matplotlib.bac kends.backend_t kagg'],
    'includes': 'matplotlib.num erix.random_arr ay',
    'excludes': ['_gtkagg', '_tkagg'],
    'dll_excludes':['libgdk-win32-2.0-0.dll',
    'libgobject-2.0-0.dll',
    'MSVCP80.dll',
    'MSVCR80.dll']
    }
    },
    data_files = dataFiles,
    windows = [
    {
    "script": "[redacted]",
    "icon_resources ": [(1, "iconJ.ico" )],
    "other_resource s": [(24,1,manifest)]
    }
    ],
    )
    [/code]
    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

    Comment

    • AdamGr
      New Member
      • Jun 2008
      • 6

      #3
      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.

      Comment

      • sbrew
        New Member
        • Dec 2008
        • 1

        #4
        py2app chokes on compressed .egg file used by MySQLdb

        I had the same issue and was able to get py2app to correctly build the .app with MySQLdb after manually unzipping the MySQLdb .egg under site-packages.

        It seems that the MySQLdb is distributed as a compressed .egg file and that confuses py2app. No special py2app recipe needed.

        To manually uncompress the .egg file, under site-packages/ instead of
        * MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg (as a binary .zip file)

        make a MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg directory and uncompress it
        Code:
        mv MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg MySQL_python-1.2.2-py2.5-macosx-10.3-fat.zip
        mkdir MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg
        mv MySQL_python-1.2.2-py2.5-macosx-10.3-fat.zip MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg
        cd MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg
        unzip MySQL_python-1.2.2-py2.5-macosx-10.3-fat.zip
        Re-run the py2app and it should pick up the MySQLdb module as expected.

        Scot

        Comment

        Working...