解决 py2app 没有 scan_code 属性的问题

Hacks Mar 06, 2016

今天用 py2app 的时候,按照国际惯例执行python setup.py py2app,但是很不幸的,发生了这个问题:

AttributeError: 'ModuleGraph' object has no attribute 'scan_code'

遂 Google 之。在 From a Python script to a portable Mac application with py2app 这个网站上找到了解决方案,如下:

If you get one of the following errors:

AttributeError: 'ModuleGraph' object has no attribute 'scan_code' AttributeError: 'ModuleGraph' object has no attribute 'load_module'

Edit the file where this error ocured (for me, it was inside the virtual environment folder, named myenv), at:

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

Look for the functions scan_code or load_module and add it an underscore before them, _scan_code and _load_module. Build again your application, it should work now :-)

Next, try to run your app, and see if it works.

大致意思就是,定位到发生问题的文件,编辑它,把 scan_codeload_module 替换成 _scan_code_load_module。重新 build,问题解决。

BTW,这个 bug 似乎好几年了……

aLPHAtOAD

太年轻,太简单,有时候幼稚。