py2app: modulegraph missing scan_code
Question: For some reason I can't explain or google, py2app crashes on me even with the
simplest examples. Im using a python 3.4.1 virtual environment created as
`Projects/Test/virtenv` which has py2app installed via pip.

Here is the output of `$pip list`:

    
    
    altgraph (0.12)
    macholib (1.7)
    modulegraph (0.12)
    pip (1.5.6)
    py2app (0.9)
    setuptools (3.6)
    

foo.py is a hello world example file saved in Projects/Test/ and contains a
single line:

    
    
    print('hello world')
    

setup.py is saved in Projects/Test as generated by `$py2applet --make-setup
foo.py`:

    
    
    """
    This is a setup.py script generated by py2applet
    
    Usage:
        python setup.py py2app
    """
    
    from setuptools import setup
    
    APP = ['foo.py']
    DATA_FILES = []
    OPTIONS = {'argv_emulation': True}
    
    setup(
        app=APP,
        data_files=DATA_FILES,
        options={'py2app': OPTIONS},
        setup_requires=['py2app'],
    )
    

Here is the full output of running `$python setup.py py2app` (all pip and
python commands were done with the virtual enviroment activated) :

    
    
    running py2app
    creating /Users/mik/Desktop/Projects/Test/build
    creating /Users/mik/Desktop/Projects/Test/build/bdist.macosx-10.8-x86_64
    creating /Users/mik/Desktop/Projects/Test/build/bdist.macosx-10.8-x86_64/python3.4-standalone
    creating /Users/mik/Desktop/Projects/Test/build/bdist.macosx-10.8-x86_64/python3.4-standalone/app
    creating /Users/mik/Desktop/Projects/Test/build/bdist.macosx-10.8-x86_64/python3.4-standalone/app/collect
    creating /Users/mik/Desktop/Projects/Test/build/bdist.macosx-10.8-x86_64/python3.4-standalone/app/temp
    creating /Users/mik/Desktop/Projects/Test/dist
    creating build/bdist.macosx-10.8-x86_64/python3.4-standalone/app/lib-dynload
    creating build/bdist.macosx-10.8-x86_64/python3.4-standalone/app/Frameworks
    *** using recipe: lxml ***
    *** using recipe: ftplib ***
    *** using recipe: sip ***
    *** using recipe: ctypes ***
    *** using recipe: xml ***
    *** using recipe: pydoc ***
    Traceback (most recent call last):
      File "setup.py", line 18, in <module>
        setup_requires=['py2app'],
      File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/Users/mik/Desktop/Projects/Test/virtenv/lib/python3.4/site-packages/py2app/build_app.py", line 659, in run
        self._run()
      File "/Users/mik/Desktop/Projects/Test/virtenv/lib/python3.4/site-packages/py2app/build_app.py", line 865, in _run
        self.run_normal()
      File "/Users/mik/Desktop/Projects/Test/virtenv/lib/python3.4/site-packages/py2app/build_app.py", line 943, in run_normal
        self.process_recipes(mf, filters, flatpackages, loader_files)
      File "/Users/mik/Desktop/Projects/Test/virtenv/lib/python3.4/site-packages/py2app/build_app.py", line 824, in process_recipes
        rval = check(self, mf)
      File "/Users/mik/Desktop/Projects/Test/virtenv/lib/python3.4/site-packages/py2app/recipes/virtualenv.py", line 80, in check
        mf.scan_code(co, m)
    AttributeError: 'ModuleGraph' object has no attribute 'scan_code'
    

Can someone please explain whats going on and how to fix it?

EDIT:
[here](https://pythonhosted.org/modulegraph/modulegraph.html#modulegraph.modulegraph.scan_code)
is the documentation for scan_code in modulegraph.py, however the file found
in Projects/Test/virtenv/lib/python3.4/site-
packages/modulegraph/modulegraph.py contains a function called _scan_code with
a leading underscore. Is this some type of change that broke py2app?

EDIT: posted
[this](https://bitbucket.org/ronaldoussoren/modulegraph/issue/22/scan_code-in-
modulegraphpy-contains-a)

EDIT: Manually removing leading underscores from a couple function definitions
in the file mentioned allowed py2app to run without error. I'm still confused
regarding what happened


Answer: I had the same problem as you and solved it now.

I referred to this [post](http://www.marinamele.com/from-a-python-script-to-a-
portable-mac-application-with-py2app).

First, search for the path

    
    
    $ /yourenv/lib/python2.7/site-packages/py2app/recipes/virtualenv.py
    

Next, open this file `virtualenv.py`, look for `scan_code` or `load_module`
and change it to `_scan_code` or `_load_module`.

Last, try to run your app

