I am trying to build my wxPython application with Python 3 using py2app. Before I updated my code to Python 3, I was able to do this successfully in Python 2.
After fixing a few initial problems (had to sys.setrecursionlimit(2000) and downgrade to Python 3.5), I got stuck here:
Traceback (most recent call last):
File "setup_pmag_gui.py", line 23, in <module>
setup_requires=['py2app'],
File "/Users/****/anaconda/lib/python3.5/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/****/anaconda/lib/python3.5/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/Users/****/anaconda/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/Users/****/my_project/.eggs/py2app-0.13-py3.5.egg/py2app/build_app.py", line 757, in run
self._run()
File "/Users/****/my_project/.eggs/py2app-0.13-py3.5.egg/py2app/build_app.py", line 967, in _run
self.run_normal()
File "/Users/****/my_project/.eggs/py2app-0.13-py3.5.egg/py2app/build_app.py", line 1075, in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
File "/Users/****/my_project/.eggs/py2app-0.13-py3.5.egg/py2app/build_app.py", line 1385, in create_binaries
mm.mm.run_file(runtime)
File "/Users/****/my_project/.eggs/macholib-1.8-py3.5.egg/macholib/MachOGraph.py", line 83, in run_file
ValueError: '/Users/****/anaconda/lib/libpython3.5.dylib' does not exist
/Users/****/anaconda/lib/libpython3.5m.dylib does exist, though. Is there a way to tell MachOGraph how to find this?
I am on OS X 10.12.4, using Anaconda Python 3.5. My version of py2app is 0.13.
This is what my setup.py file looks like:
from setuptools import setup
import sys
import os
directory = os.getcwd()
sys.setrecursionlimit(3000)
APP = ['programs/pmag_gui.py']
DATA_FILES = [('', ['dialogs/help_files', 'pmagpy/data_model', 'programs/images'])]
OPTIONS = {'argv_emulation': False,
'iconfile': os.path.join(directory, 'programs', 'images', 'text_x_xslfo.icns')}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
After reading the Tweaking your Info.plist py2app documentation, and this question, I tried adding to OPTIONS:
'plist': dict(PyRuntimeLocations=['/Users/****/anaconda/lib/libpython3.5m.dylib'])
But I get the same exact error message as before.
Any suggestions on how to solve this, or what documentation to look at?
I had same problem with miniconda and py2app. I could fix it by creating a symlink!
ln -s /path/to/lib/libpython3.5m.dylib /path/to/lib/libpython3.5.dylib
Related
I am trying to create an executable for a script I have already written. It will be used by a coworker who doesn't have python on their machine, so I want to create an executable to make their life easier. I'm currently just trying to get py2exe to work and create an executable for a simple script that simply prints hello world and the constant e from the math module (just to get an idea for how py2exe works).
My setup script is as follows:
from distutils.core import setup
import py2exe
import math
setup(
console=[{'script':'hello.py'}],
options={
'py2exe':{
'packages' : ['math'],
'bundle_files':1
},
},
version='1.0.0'
)
where hello.py is simply:
import math
print('hello world!')
print(f'Here is e: {math.exp(1)}')
The error comes from this stack after I call "python setup.py py2exe" in cmd
Traceback (most recent call last):
File ".\setup.py", line 5, in <module>
setup(
File ".\Anaconda3\lib\site-packages\setuptools\_distutils\core.py", line 148, in setup
return run_commands(dist)
File ".\Anaconda3\lib\site-packages\setuptools\_distutils\core.py", line 163, in run_commands
dist.run_commands()
File ".\Anaconda3\lib\site-packages\setuptools\_distutils\dist.py", line 967, in run_commands
self.run_command(cmd)
File ".\Anaconda3\lib\site-packages\setuptools\dist.py", line 1214, in run_command
super().run_command(command)
File ".\Anaconda3\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
cmd_obj.run()
File ".\Anaconda3\lib\site-packages\py2exe\distutils_buildexe.py", line 192, in run
self._run()
File ".\Anaconda3\lib\site-packages\py2exe\distutils_buildexe.py", line 273, in _run
builder.build()
File ".\Anaconda3\lib\site-packages\py2exe\runtime.py", line 250, in build
self.build_archive(exe_path)
File ".\Anaconda3\lib\site-packages\py2exe\runtime.py", line 490, in build_archive
base = dist_path.rsplit('\\', 1)[0]
AttributeError: 'NoneType' object has no attribute 'rsplit'
To covert a .py file to .exe you need to install auto-py-to-exe
Windows
pip install auto-py-to-exe
After it is installed, open cmd then type
auto-py-to-exe
Then specify the path of the script and the location where you want to save the .exe file.
I'm trying to compile python script to exe.
My script - hello.py:
print("hello")
My setup.py:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
name = 'hello',
description = 'hello script',
version = '1.0',
options = {'py2exe': {'bundle_files': 1, 'compressed': True,'dist_dir': ".",'dll_excludes':['w9xpopen.exe']}},
console = [{'script': r"hello.py"}],
zipfile = None,
)
I run:
py -3 setup.py install
The error:
py -3 setup.py install
running install
running build
running install_egg_info
Removing C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\hello-1.0-py3.7.egg-info
Writing C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\hello-1.0-py3.7.egg-info
running py2exe
Traceback (most recent call last):
File "setup.py", line 19, in <module>
zipfile = None,
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\runtime.py", line 160, in analyze
self.mf.import_hook(modname)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
Do you know how to resolve this error?
py2exe seems to support up to Python 3.4 (thanks Michael Butscher)
However, there are other libraries such as Pyinstaller which work just fine, and are compatible with a variety of Python versions (from Python 2.7 to 3.5+)
Check it out, it's actually really easy :)
https://pyinstaller.readthedocs.io/en/stable/
so I've created a virtual environment in my iterm2 window. this is the ques I asked earlier which has not been solved yet and my app is not running is alias modeso i tried to do the whole process again but it was showing error with plistlib so that was fixed by this answer I tried this whole process again which means I did this all this before but my app was not working so i deleted my py2app and some venv's got deleted to I downloaded miniconda3 again and then it was working until it comes to running the app even in alias mode . but I continued and deleted the dist and build and when I executed
python setup.py py2app but then i got this error
Traceback (most recent call last):
File "setup.py", line 18, in <module>
setup_requires=['py2app'],
File "/Users/divyabansal/divya/lib/python3.7/site-packages/setuptools/__init__.py", line
145, in setup
return distutils.core.setup(**attrs)
File "/Users/divyabansal/miniconda3/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/divyabansal/miniconda3/lib/python3.7/distutils/dist.py", line 966, in
run_commands
self.run_command(cmd)
File "/Users/divyabansal/miniconda3/lib/python3.7/distutils/dist.py", line 985, in
run_command
cmd_obj.run()
File "/Users/divyabansal/divya/lib/python3.7/site-packages/py2app/build_app.py", line 756,
in run
self._run()
File "/Users/divyabansal/divya/lib/python3.7/site-packages/py2app/build_app.py", line 966,
in _run
self.run_normal()
File "/Users/divyabansal/divya/lib/python3.7/site-packages/py2app/build_app.py", line 1074,
in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
File "/Users/divyabansal/divya/lib/python3.7/site-packages/py2app/build_app.py", line 1384,
in create_binaries
mm.mm.run_file(runtime)
File "/Users/divyabansal/divya/lib/python3.7/site-packages/macholib/MachOGraph.py", line 89,
in run_file
raise ValueError("%r does not exist" % (pathname,))
ValueError: '/Users/divyabansal/miniconda3/lib/libpython3.7.dylib'
does not exist
please help me with this problem
Thank You!
This problem can often be fixed by creating a symlink, see here for more.
ln -s /path/to/lib/libpython3.7m.dylib /path/to/lib/libpython3.7.dylib
For the above command replace it with your own path.
Objective (End-Goal):
I want to create a stand-alone executable Python script (only one file) that includes NumPy and SciPy dependencies for my application.
Background:
From my understanding, to create an executable script in Python - there are three options that are available:
PyInstaller
Py2exe
CxFreeze
I went ahead and tried Py2exe for my development. It appears that CxFreeze does not support the single-file option (from the documentation here). I also considered the option of using PyInstaller, but ran into issues regarding missing DLLs (similar to what is found here). The issue continued to persist even after installing the Microsoft Visual C++ 2010 Redistributable Package in my laptop.
I followed the tutorial to use Py2exe here and was able to get a dummy script executable (Hello World!) working. However, I tried to re-modify the setup.py script specific to my application to include numpy and scipy dependencies (see below):
from distutils.core import setup
import py2exe,sys,numpy,scipy
sys.argv.append('py2exe')
setup(
console=['Application.py'],
options={
'py2exe': {
'includes':['numpy','scipy','scipy.integrate','scipy.special.*','scipy.linalg.*'],
'bundle_files':1,
'compressed':True
}
},
zipfile=None)
This is the resulting error I received when I tried running the script:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.1.4\helpers\pydev\pydev_run_in_console.py", line 52, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2018.1.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/prest/PycharmProjects/Application/setup.py", line 15, in <module>
zipfile=None
File "C:\Python34\lib\distutils\core.py", line 149, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\runtime.py", line 164, in analyze
mf.import_hook(modname)
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\mf3.py", line 337, in _find_and_load
raise ImportError(name)
ImportError: scipy.linalg.*
These are the versions that I am using relevant for my application:
Python 3.4
NumPy 1.14.5
SciPy 1.1.0
Question:
Can anyone provide any insight as to why I am receiving this error and any next steps to address this? I appreciate any input!
Thanks,
Preston
Closing - went ahead and use PyInstaller for the single-file executable. I re-modified my script to address specific dependencies (only used NumPy).
Below is what has appeared as an error to me after typing in python setup.py py2app. I'm on a mac. I've spent hours reading tutorials, making sure both py2app and pyapplet were set up, and following the tutorials, I don't know what's wrong. Here's the error:
running py2app
Traceback (most recent call last):
File "setup.py", line 18, in <module>
setup_requires=['py2app'],
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py2app-0.7.3-py2.6.egg/py2app/build_app.py", line 502, in run
if sysconfig.get_config_var('PYTHONFRAMEWORK') is None:
AttributeError: 'NoneType' object has no attribute 'get_config_var'
And here is my setup.py
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['kradio.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Both the program and the setup are located in the user directory.