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.
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 have already create an issue in github. But no one reply.
The question is:
I runpython3 setup.py py2app and the error:
Traceback (most recent call last):
File "/Users/th/source/duomai/send_email.py/setup.py", line 14, in <module>
setup(
File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/usr/local/Cellar/python#3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/Cellar/python#3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/local/Cellar/python#3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 925, in run
self._run()
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 1147, in _run
self.run_normal()
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 1244, in run_normal
self.process_recipes(mf, filters, flatpackages, loader_files)
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 1099, in process_recipes
rval = check(self, mf)
File "/usr/local/lib/python3.9/site-packages/py2app/recipes/sip.py", line 111, in check
mf.import_hook("sip", m)
File "/usr/local/lib/python3.9/site-packages/modulegraph/modulegraph.py", line 1114, in import_hook
q, tail = self._find_head_package(parent, name, level)
File "/usr/local/lib/python3.9/site-packages/modulegraph/modulegraph.py", line 1215, in _find_head_package
raise ImportError("No module named " + qname)
ImportError: No module named sip
And my setup.py
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['cli.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
It's seems like qt relative. But I didn't used qt, I just use the tkinter...
The detail log is long, I create an attach. https://www.dropbox.com/s/4pcc9zv7dgoq37j/log.txt?dl=0
How to fix this?
Try adding the packages to your options in the setup file, like this:
OPTIONS = {
'argv_emulation': True,
'packages':['tkinter']}
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/
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
Compiling .pyx files was working fine but suddenly it started raising error when I type:
python setup.py build_ext --inplace
I get the error:
c:\Python27\cython\helloworld>python setup.py build_ext --inplace
running build_ext
cythoning hello.pyx to hello.c
Traceback (most recent call last):
File "setup.py", line 8, in <module>
ext_modules = [Extension("hello", ["hello.pyx"])]
File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 163,
in run
_build_ext.build_ext.run(self)
File "C:\Python27\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 170,
in build_extensions
ext.sources = self.cython_sources(ext.sources, ext)
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 317,
in cython_sources
full_module_name=module_name)
File "C:\Python27\lib\site-packages\Cython\Compiler\Main.py", line 605, in com
pile
return compile_single(source, options, full_module_name)
File "C:\Python27\lib\site-packages\Cython\Compiler\Main.py", line 546, in com
pile_single
return run_pipeline(source, options, full_module_name)
File "C:\Python27\lib\site-packages\Cython\Compiler\Main.py", line 386, in run
_pipeline
import Pipeline
File "C:\Python27\lib\site-packages\Cython\Compiler\Pipeline.py", line 7, in <
module>
from Visitor import CythonTransform
File "Visitor.py", line 9, in init Cython.Compiler.Visitor (Cython\Compiler\Vi
sitor.c:12838)
File "C:\Python27\lib\site-packages\Cython\Compiler\Nodes.py", line 6, in <mod
ule>
cython.declare(sys=object, os=object, copy=object,
AttributeError: 'module' object has no attribute 'declare'
I tried running it on a simple .pyx file helloworld:
def say_hello_to(name):
print "Hello %s!" %name
with the setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("hello", ["hello.pyx"])]
)
It already worked several times, something has changed but as I Googled and searched the issue I couldn't find any information. I'm using Python 2.7 64 bits, latest version of Cython and to compile the file I use Windows SDK C/C++ compiler and prepare the environment by running:
C:\Program Files\Microsoft SDKs\Windows\v7.0>set DISTUTILS_USE_SDK=1
C:\Program Files\Microsoft SDKs\Windows\v7.0>setenv /x64 /release
Any ideas of what might have happened? Tnx in advance!
I got the same error when running from a python script:
os.system("python setup.py build_ext --inplace")
while
python setup.py build_ext --inplace
worked from command promt.
The reason was that the name of my test package was "cython"... stupid me
I have had the same error.
Worked on it for one whole day until I have realized that I have followed some blog entry to create a cython.py file in my directory holding some information how to compile.
I do not recall where I found this but by removing this file everything works fine
I'm not sure this helps, but when I got this error I deleted all .pyc files and ran the script again via IDLE (opened in IDLE and clicked F5) and then it worked just fine.