hello there.

in order to gain experience I started a small python project. it is an more or less simple, collaborative address book (Snow Leo and Python 2.6.1).

the final step is to create a standalone programm.

to create the address book I used PyQt4 and MySQLdb. since py2app chokes heavily on MySQLdb, I tried pyinstaller.

File "<string>", line 60, in <module>
  File "PyInstaller/loader/iu.py", line 449, in importHook
  File "PyInstaller/loader/iu.py", line 539, in doimport
  File "Friver/build/pyi.darwin/Friver/outPYZ1.pyz/gui", line 6, in <module>
  File "PyInstaller/loader/iu.py", line 449, in importHook
  File "PyInstaller/loader/iu.py", line 539, in doimport
  File "Friver/build/pyi.darwin/Friver/outPYZ1.pyz/handler", line 3, in <module>
  File "PyInstaller/loader/iu.py", line 449, in importHook
  File "PyInstaller/loader/iu.py", line 539, in doimport
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
  File "PyInstaller/loader/iu.py", line 449, in importHook
  File "PyInstaller/loader/iu.py", line 539, in doimport
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 3, in __bootstrap__
  File "PyInstaller/loader/iu.py", line 468, in importHook
  ImportError: No module named pkg_resources

why does pyinstaller not add pkg_resources.py?

my app.spec:

# -*- mode: python -*-

a = Analysis([os.path.join(HOMEPATH,'support','_mountzlib.py'), os.path.join(CONFIGDIR,'support','useUnicode.py'), 'src/Friver.py'],
             pathex=['/Volumes/Home/davo/Desktop/trunk'],
             hookspath=None)
pyz = PYZ(a.pure)
exe = EXE( pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'Friver'),
          debug=False,
          strip=None,
          upx=True,
          console=True )

import sys
if sys.platform.startswith("darwin"):
    app = BUNDLE(exe,
                 appname='Friver',
                 version=1)

I countered every obsticle, came so far...I just don't want to give up now and recode using QtSql.

thank you in advance :)

just out of curiosity, is there another workaround for py2app and MySQLdb other than unziped *.egg-file? because this one isn't working (importerror _mysql). adding _mysql to the apps site-packages by hand isn't working ether. it results in an pkg_resources error:

[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	  File "MySQLdb/__init__.pyc", line 19, in <module>
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 4, in __bootstrap__
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 835, in resource_filename
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	    self, resource_name
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 1297, in get_resource_filename
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	    "resource_filename() only supported for .egg, not .zip"
[0x0-0x1d11d1].org.pythonmac.unspecified.Friver[4527]	NotImplementedError: resource_filename() only supported for .egg, not .zip

maybe these 2 problems are somehow linked...

Recommended Answers

All 3 Replies

its been a long time, but I recently solved the problem.

it is because of python-mysqldb for mac. it somehow installs itself badly but I am not certain if this is the root of my problem. I installed mysqlserver and compiled from source. on windows and linux it is not a problem at all. just use the provided .exe or your favourite package-manager. anyways, here is the solution:

first of all you have to find and extract the python-mysqldb egg. unzip will do the job. just rename the egg to whatever you want and append ".egg" to the extracted folder. python-mysqldb will still work...

in your main programm:

import mysqldb, _mysql, pkg_resources

add the following to your app or appfolder (I am not using the one-file-option):

cp _mysql.so app_dir/
cp -r qt_menu.nib app_dir/

on the system the app should run standalone you have to create an alias

sudo ln -s app_dir/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

I am sure there are other ways but this works pretty well for me. you only have to do this for mac. since installing python-mysqldb for mac is pretty messy it is not realy an option for less experienced users.

I think the threadname does not realy correspond with the actual problem. if some mod were able to change it IMHO "pyinstaller and mysqldb" would be more fitting.

greetings from germany

P.S.: if you do not use PyQt4 you wont need the qt_menu.nib

commented: thanks for sharing the solution +13

Great man! You saved me!

I am thinking about buying the new mac air. Many thanks for the info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.