问题
I have some troubles with py2app; for some reason I have always the same error for all scripts that I developed. At the moment I am using last MacPorts version and after two days of testing I cannot figure out what is wrong.
One of the setup.py file for py2app is:
from setuptools import setup
APP = ['main.py']
OPTIONS = {'argv_emulation': True, 'includes': ['sip', 'PyQt4._qt', 'PyQt4.QtCore', 'PyQt4.QtGui'],
'excludes': ['PyQt4.QtDesigner', 'PyQt4.QtNetwork', 'PyQt4.QtOpenGL', 'PyQt4.QtScript', 'PyQt4.QtSql', 'PyQt4.QtTest', 'PyQt4.QtWebKit', 'PyQt4.QtXml', 'PyQt4.phonon']}
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
And this is the log:
python setup.py py2app
running py2app
creating /Users/opensw/SkyDrive/SISSA/Kymograph/build/bdist.macosx-10.6-intel/python2.7-standalone/app
creating /Users/opensw/SkyDrive/SISSA/Kymograph/build/bdist.macosx-10.6-intel/python2.7-standalone/app/collect
creating /Users/opensw/SkyDrive/SISSA/Kymograph/build/bdist.macosx-10.6-intel/python2.7-standalone/app/temp
creating build/bdist.macosx-10.6-intel/python2.7-standalone/app/lib-dynload
creating build/bdist.macosx-10.6-intel/python2.7-standalone/app/Frameworks
*** using recipe: virtualenv ***
WARNING: ImportError in sip recipe ignored: No module named matplotlib-1
WARNING: ImportError in sip recipe ignored: No module named scipy-0
*** using recipe: sip ***
*** using recipe: matplotlib ***
*** using recipe: scipy ***
Traceback (most recent call last):
File "setup.py", line 10, in <module>
setup_requires=['py2app'],
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/opensw/SkyDrive/SISSA/Kymograph/py2app-0.7.3-py2.7.egg/py2app/build_app.py", line 553, in run
self._run()
File "/Users/opensw/SkyDrive/SISSA/Kymograph/py2app-0.7.3-py2.7.egg/py2app/build_app.py", line 741, in _run
self.run_normal()
File "/Users/opensw/SkyDrive/SISSA/Kymograph/py2app-0.7.3-py2.7.egg/py2app/build_app.py", line 816, in run_normal
self.process_recipes(mf, filters, flatpackages, loader_files)
File "/Users/opensw/SkyDrive/SISSA/Kymograph/py2app-0.7.3-py2.7.egg/py2app/build_app.py", line 710, in process_recipes
find_needed_modules(mf, packages=rval['packages'])
File "build/bdist.macosx-10.6-intel/egg/modulegraph/find_modules.py", line 199, in find_needed_modules
TypeError: 'NoneType' object has no attribute '__getitem__'
Thanks for any help.
回答1:
The problem is that some bad input has been passed to the algorithm which attempts to detect dependancies in order to package them into your app - one of the places where I have had trouble with this has been in use of github flavoured markdown in package README.md files.
This is a general guide to debugging setup.py issues, or actually python issues in general.
Run it again in interactive mode, i.e.
python -i setup.py py2app
. Oncesetup.py
exits you will find yourself in a python prompt.Run
from pdb import pm; pm()
. You should now find yourself at a debug prompt.Type
up
and hit enter - you are now a frame higher in the stack - you can typelist
to see where in the source code the current frame is positioned, andargs
to see the arguments passed to the current frame (usually a function or method). You can also run python commands to inspect the current state, and runpp var
to pretty-print that variable.Once you have repeated the above step a few times you will find where the error is encountered - in the case I encountered where it was a README file I found a variable called
lineno
which gave the line of my README file which caused the error. If your problem is a module import, it'll probably be something different, but my instinct is that you'll find yourself looping over thepackages
argument seen in your stack trace, and the current list item will be the key to your problem.
来源:https://stackoverflow.com/questions/16131500/py2app-error-in-find-needed-modules-typeerror-nonetype-object-has-no-attribu