Py2App: Alias mode works, but deployment doesn't - python

I'm trying to deploy my python application using py2app.
I created the setup file using : py2applet --make-setup MyApplication.py
Then I did this to test it : python setup.py py2app -A
That worked as well. My GUI program runs.
When I try the last step: python setup.py py2app
I get this fat error.
Traceback (most recent call last):
File "setup.py", line 18, in <module>
setup_requires=['py2app'],
File "/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/site-packages/py2app/build_app.py", line 659, in run
self._run()
File "/usr/local/lib/python2.7/site-packages/py2app/build_app.py", line 865, in _run
self.run_normal()
File "/usr/local/lib/python2.7/site-packages/py2app/build_app.py", line 959, in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
File "/usr/local/lib/python2.7/site-packages/py2app/build_app.py", line 1214, in create_binaries
platfiles = mm.run()
File "/usr/local/lib/python2.7/site-packages/macholib/MachOStandalone.py", line 105, in run
mm.run_file(fn)
File "/usr/local/lib/python2.7/site-packages/macholib/MachOGraph.py", line 84, in run_file
self.scan_node(m)
File "/usr/local/lib/python2.7/site-packages/macholib/MachOGraph.py", line 110, in scan_node
m = self.load_file(filename, caller=node)
File "/usr/local/lib/python2.7/site-packages/macholib/MachOGraph.py", line 93, in load_file
newname = self.locate(name, loader=caller)
File "/usr/local/lib/python2.7/site-packages/macholib/MachOStandalone.py", line 23, in locate
newname = super(FilteredMachOGraph, self).locate(filename, loader)
File "/usr/local/lib/python2.7/site-packages/macholib/MachOGraph.py", line 49, in locate
loader=loader.filename)
TypeError: dyld_find() got an unexpected keyword argument 'loader'
Why is this happening? I've spend the last few hours trying to deploy. No luck with py2app, cx_freeze, etc.

Here is a workaround: edit the file MachOGraph.py which in your case is located there:
/usr/local/lib/python2.7/site-packages/macholib/MachOGraph.py
Search for the term loader=loader.filename) and replace it with loader_path=loader.filename)
Credits goes to David Goldenberg for its post on bitbucket.org. https://bitbucket.org/ronaldoussoren/py2app/issues/137/py2app-problems-using-enthought-python

Pillow was the problem. Py2Applet doesn't play nice with it. Got rid of Pillow, and all is well.

Related

The following error occurred while using py2exe

python setup.py py2exe
The following error occurred while using py2exe.
The source code for setup.py:
# setup.py
from distutils.core import setup
import py2exe
setup(console=['python.py'])
I'm trying to make python.py exe.
the mistake of this moment:
E:\ajil\Program\Query>python setup.py py2exe
running py2exe
Traceback (most recent call last):
File "setup.py", line 4, in <module>
setup(console=['python.py'])
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\runtime.py", line 160, in analyze
self.mf.import_hook(modname)
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\dashzeveg.b\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
Use Pyinstaller that will help you for this. pyinstaller
pip install PyInstaller
pyinstaller <options> <ScriptName.py>
pyinstaller myscript.py # Normal Usage
pyinstaller --onefile myscript.py # To create single executable

NameError py2app in modulegraph

I'm trying to use py2app to create a standalone application of mac. When I`m using the alias mode everything work fine, but when I try to
python setup.py py2app
I receive this error:
Traceback (most recent call last):
File "setup.py", line 21, in <module>
setup_requires=['py2app'],
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/py2app/build_app.py", line 659, in run
self._run()
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/py2app/build_app.py", line 865, in _run
self.run_normal()
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/py2app/build_app.py", line 943, in run_normal
self.process_recipes(mf, filters, flatpackages, loader_files)
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/py2app/build_app.py", line 824, in process_recipes
rval = check(self, mf)
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/py2app/recipes/virtualenv.py", line 86, in check
mf._scan_code(co, m)
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/modulegraph/modulegraph.py", line 1543, in _scan_code
self._scan_bytecode(co, m)
File "/Users/robert/Envs/py36/lib/python3.6/site-packages/modulegraph/modulegraph.py", line 1570, in _scan_bytecode
n = len(code)
NameError: name 'code' is not defined
My version of Python 3.5, py2app 0.10, module graph 0.13. Has anyone encountered a similar one, and how I can solve it?
P.S. Sorry for my bad English.
I had the same issue.
This issue will be fixed in moudulegraph 0.14
If you can't wait you can pull from the repo any point after this commit:
https://bitbucket.org/ronaldoussoren/modulegraph/commits/32c6c60f9dcdb106219a1476218e0d364cb11255

compiling python script to exe with py2exe, getting error

So I have a script called papercutter.py and a setup.py that is set up as follows according to the py2exe tutorial:
from distutils.core import setup
import py2exe
setup(console=['papercutter.py'])
So following the tutorial, i run python setup.py py2exe and it looks successful:
c:\Codes>python setup.py install
running install
running build
running install_egg_info
Removing C:\Python\Lib\site-packages\UNKNOWN-0.0.0-py3.6.egg-info
Writing C:\Python\Lib\site-packages\UNKNOWN-0.0.0-py3.6.egg-info
but when I run the next step, python setup.py py2exe, I get error:
c:\Codes>python setup.py py2exe
running py2exe
Traceback (most recent call last):
File "setup.py", line 4, in <module>
setup(console=['papercutter.py'])
File "C:\Python\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Python\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Python\lib\site-packages\py2exe\runtime.py", line 157, in analyze
self.mf.import_package(modname[:-2])
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 91, in import_package
self.import_hook(name)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 320, in _ find_and_load
self._scan_code(module.__code__, module)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 352, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 381, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
What am I doing wrong here?
Note: this is the tutorial I am following: http://www.py2exe.org/index.cgi/Tutorial
Also note: I am using py2exe 0.9.2.0 and python 3.6.0. I think these should be fine together.
The answer is at the bottom of the Traceback. Seems like you have an indexing problem with a tuple. Indexes are 0 based in Python.
Currently py2exe supports Python up to 3.4

Python traceback points to non-existent file

I'm trying to run a setup.py script (for mnemosyne). The script fails, and I'm pretty sure I know how to fix the problem, if I could only find the file to edit. The problem is that the traceback points to a non-existent file:
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOGraph.py", line 49, in locate
loader=loader.filename)
TypeError: dyld_find() got an unexpected keyword argument 'loader'
I believe that should be loader_path. The problem is that MachOGraph.py file doesn't exist -- not anywhere in my current path, or in my anaconda distribution. There is a build/bdist.macosx-10.5-x86_64/ directory, but no egg. There are a few MachOGraph.py files on my system, but none of them have that line. Nothing under this directory contains the string loader.filename.
What's going on? How can I find that file?
For completeness, here is the complete traceback:
Traceback (most recent call last):
File "/Users/mike/.continuum/anaconda/lib/python2.7/site-packages/ipdb/__main__.py", line 157, in main
pdb._runscript(mainpyfile)
File "/Users/mike/.continuum/anaconda/lib/python2.7/pdb.py", line 1233, in _runscript
self.run(statement)
File "/Users/mike/.continuum/anaconda/lib/python2.7/bdb.py", line 400, in run
exec cmd in globals, locals
File "<string>", line 1, in <module>
File "setup.py", line 241, in <module>
app = py2app_app
File "/Users/mike/.continuum/anaconda/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/Users/mike/.continuum/anaconda/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/Users/mike/.continuum/anaconda/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/src/Mnemosyne-2.3.1/py2app-0.8.1-py2.7.egg/py2app/build_app.py", line 654, in run
self._run()
File "/usr/local/src/Mnemosyne-2.3.1/py2app-0.8.1-py2.7.egg/py2app/build_app.py", line 860, in _run
self.run_normal()
File "/usr/local/src/Mnemosyne-2.3.1/py2app-0.8.1-py2.7.egg/py2app/build_app.py", line 950, in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
File "/usr/local/src/Mnemosyne-2.3.1/py2app-0.8.1-py2.7.egg/py2app/build_app.py", line 1110, in create_binaries
platfiles = mm.run()
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOStandalone.py", line 105, in run
mm.run_file(fn)
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOGraph.py", line 84, in run_file
self.scan_node(m)
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOGraph.py", line 110, in scan_node
m = self.load_file(filename, caller=node)
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOGraph.py", line 93, in load_file
newname = self.locate(name, loader=caller)
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOStandalone.py", line 23, in locate
newname = super(FilteredMachOGraph, self).locate(filename, loader)
File "build/bdist.macosx-10.5-x86_64/egg/macholib/MachOGraph.py", line 49, in locate
loader=loader.filename)
TypeError: dyld_find() got an unexpected keyword argument 'loader'
This issue is caused by Pillow, you can use pip uninstall Pillow to uninstall it, then this question will disappear.
Python takes the filename as reported in the bytecode when printing a traceback. In this case, the bytecode contains filenames that are generated to produce a Python egg, a format that contains at least the bytecode files. These paths reflect the build directory relative to the package as it was built.
In this case, it is the py2app installer that includes macholib as a installation requirement; setuptools downloads the source code for that library and produces an egg on demand, in the same location as the py2app egg. I'd look in /usr/local/src/Mnemosyne-2.3.1/py2app-0.8.1-py2.7.egg for a macholib-1.6-py2.7.egg directory.
With macholib1.7, from line 46 of **/MachOGraph.py...:
try:
fn = dyld_find(filename, env=self.env,
executable_path=self.executable_path,
loader=loader.filename)
self.trans_table[(loader.filename, filename)] = fn
except ValueError:
return None
Change line 49 to:
loader_path=loader.filename)

Python setup.py install throwing zipimport.ZipImportError

I run the following command in terminal sudo python2.6 setup.py install and after some output I get the below error.
Traceback (most recent call last):
File "setup.py", line 16, in <module>
packages=find_packages()
File "/opt/python2.6/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/opt/python2.6/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/opt/python2.6/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/install.py", line 76, in run
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/install.py", line 104, in do_egg_install
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/easy_install.py", line 211, in run
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/easy_install.py", line 427, in easy_install
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/easy_install.py", line 478, in install_item
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/easy_install.py", line 519, in process_distribution
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 570, in resolve
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 2149, in requires
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 2141, in _dep_map
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 2560, in split_sections
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 1854, in yield_lines
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 2163, in _get_metadata
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 1181, in get_metadata_lines
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 1178, in get_metadata
File "/opt/python2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 1238, in _get
zipimport.ZipImportError: bad local file header in /opt/python2.6/lib/python2.6/site-packages/businesscommon-5.63-py2.6.egg
I ran the command unzip -t /opt/python2.6/lib/python2.6/site-packages/businesscommon-5.63-py2.6.egg to see if the EGG file is a valid ZIP file and it returned 'No errors detected'.
I've done some research on zipimport.ZipImportError but can't seem to figure how really to debug or fix it. I don't have much experience with Python so any help or advice would be appreciated.
Looks like all I needed to do was run sudo python2.5 setup.py install instead of sudo python2.6 setup.py install
Notice that I was oringally using python2.6 instead of python2.5.

Categories