473,624 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

py2app chokes on MySQLdb

6 New Member
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:
Expand|Select|Wrap|Line Numbers
  1.  python setup.py py2app 
and then run the resulting executable, I get the error:
Expand|Select|Wrap|Line Numbers
  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
Expand|Select|Wrap|Line Numbers
  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
Jun 27 '08 #1
3 3438
jlm699
314 Contributor
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:

Expand|Select|Wrap|Line Numbers
  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. )
  61.  
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
Jun 27 '08 #2
AdamGr
6 New Member
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.
Jun 29 '08 #3
sbrew
1 New Member
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
Expand|Select|Wrap|Line Numbers
  1. 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
  2. mkdir MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg
  3. 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
  4. cd MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg
  5. 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
Dec 2 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2581
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to "conflicting header files," but I don't know what to do about conflicting header files, or where I would find them, and once I found them, which ones to remove. I have compiled MySQL 4.1 and installed into /usr/local/mysql, but since have moved to a Fink...
0
1450
by: Bob Swerdlow | last post by:
I'm trying to move my application from bundlebuilder to py2app. I upgraded to PyObjC 1.2, which include py2app 1.7, but I got the following error. I saw a note on the py2app site that earlier versions need to be removed before the upgrade, so I deleted the py2app directory and downloaded and installed it separately, but got the same result. How do I get it to find this boot_app.py file? Thanks, Bob
1
2531
by: bex | last post by:
Im baffled about this one... Im running OS 10.3, and Python 2.3. I installed py2app 0.17 and never used it, then installed py2app 0.2. It refuses to work. None of the samples will build. Observe: $ pwd /Developer/Python/py2app/Examples/pygame $ python setup.py py2app Traceback (most recent call last):
3
2171
by: bsharitt | last post by:
I'm trying to get Bittornado to run on Mac OS X (10.4 with Python 2.3.5) but I've only ever dealt with Python at lower lever scripting stuff, never wxPython or another GUI stuff. py2app is supposed to be the tool to create Mac friendly Python applications(like py2exe on Windows), but the documentation for py2app doesn't seem to be much help. The setup.py script that comes with BitTornado doesn't run when I type python setup.py py2app and...
0
2015
by: Richard Taylor | last post by:
User-Agent: OSXnews 2.07 Xref: number1.nntp.dca.giganews.com comp.lang.python:437315 Hi I am trying to use py2app (http://undefined.org/python/) to package a gnome-python application called gramps (http://www.gramps-project.org) for MAC OS X.
3
2574
by: SPE - Stani's Python Editor | last post by:
Hi, I'm creating a GUI program with wxPython which will be distributed for Mac and Windows. The audience of the program is not technical at all (eg they've never heard about Python yet ;-), so everything should go automatically. The program should be able to update itself and to update its database (collection of .txt files). These are two separated things and don't happen simultaneously. I thought of the following:
2
1509
by: loren.davie | last post by:
Hi, I'm attempting to build a small app that uses pythoncard for a gui layer. The intention is to use py2app to construct an .app bundle for the Mac. I'm running OS 10.4 on an Intel MacBook Pro. I'm using the default installed Python 2.3 The .app bundle appears to build, but when I start up it fails - checking the console reveals that it can't find the "wx" package, as its called from some pythoncard code. (The app launches just...
2
2312
by: James Stroud | last post by:
Hello All, I am trying to create a semi-standalone with the vendor python on OS X 10.4 (python 2.3.5). I tried to include some packages with both --packages from the command and the 'packages' option in setup.py. While the packages were nicely included in the application bundle in both cases (at Contents/Resources/lib/python2.3/), they were not found by python when the program was launched, giving the error: "ImportError: No module...
1
1897
by: Joe Strout | last post by:
I'm trying to use py2app to convert the pySketch wxPython example into a stand-alone OS X app. I've found the documentation at <http://undefined.org/python/py2app.html like this: #!/usr/bin/env python """ setup.py - script for building a bundled OS X application Usage: % python setup.py py2app
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.