1. Ronald Oussoren
  2. py2app
  3. Issues


Issue #47 new

py2app should byte-compile the script file

created an issue


I am looking at creating an app that parses a config file and does stuff..

When I run the app directly, it works well, but when I create a binary using py2app, the configparser doesn't parse anymore. The solution to this problem eludes me.

I have a very distilled down version of this problem with just a single script.

The python script - foo.py

The script:

import ConfigParser

a = ConfigParser.ConfigParser()
r = a.read("foo.cfg")
print r
print a
print a.sections()
for s in a.sections():
print s
for i in a.items(s):
    print "\t", i

The config file: foo.cfg

The file:




The execution from source:


Rajesh-Vaidheeswarrans-MacBook-Pro:scratch rvaidhee$ python foo.py
<ConfigParser.ConfigParser instance at 0x10997af38>
['main', 'section1', 'section2']
('hello', 'world')
('cup', 'cake')
('tom', 'jerry')

The app was created as follows:

python setup.py py2app --includes ConfigParser --argv-emulation -a

I tried not including the ConfigParser first, and then tried including it. Both produce the same result.

The execution from the binary app:

Rajesh-Vaidheeswarrans-MacBook-Pro:scratch rvaidhee$        ./dist/foo.app/Contents/MacOS/foo

[] <ConfigParser.ConfigParser instance at 0x102c5a3f8> []

As you can see above, the sections and file list are both empty

The setup.py file to create the app


This is a setup.py script generated by py2applet

python setup.py py2app

from setuptools import setup

APP = ['foo.py']
OPTIONS = {'argv_emulation': True}

    options={'py2app': OPTIONS},

Comments (6)

  1. Ronald Oussoren repo owner

    This is almost certainly related to the current working directory of your script: py2app by default changes the current working directory to the 'Resources' directory inside of the application bundle.

    The reason for this is that when you double-click the application icon (the usual way to start the application) the Finder will start your application with an arbitrary working directory (although IIRC this was the root directory from OSX 10.0 until now).

    You have to use an absolute path to read the configuration file.

  2. RajeshVaidheeswarran reporter
    • changed status to open

    Thank you! You were right. It works with an absolute path.

    However, I see that py2app uses the pyc files inside a zip file and also copies the actual script to Resources. Is there any way to make it can actually embed the zip inside the binary?

  3. Ronald Oussoren repo owner

    The easiest workaround to include the script in the zipfile: add a wrapper script that just imports the real script.

    That said, I will add the script to the zipfile in a future release but haven't gotten around to that yet.

  4. Log in to comment