py2app - IndexError: tuple index out of range - python

Getting the following error when trying to build my application. My code runs smoothly inside VScode (running the python file directly). I've looked online and I can't seem to find anyone who's had this error pop up. It used to happen to me when I wasn't in my virtual environment, but I definitely am now (source venv/bin/activate). What could it be? Thanks
Traceback (most recent call last):
File "/Users/wiggly/Desktop/twitterBot/setup.py", line 14, in <module>
setup(
^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/distutils/core.py", line 148, in setup
dist.run_commands()
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/distutils/dist.py", line 985, in run_command
cmd_obj.run()
^^^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/build_app.py", line 967, in run
self._run()
^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/build_app.py", line 1197, in _run
self.run_normal()
^^^^^^^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/build_app.py", line 1294, in run_normal
self.process_recipes(mf, filters, flatpackages, loader_files)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/build_app.py", line 1143, in process_recipes
rval = check(self, mf)
^^^^^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/recipes/detect_dunder_file.py", line 54, in check
scan_bytecode_loads(names, node.code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/recipes/detect_dunder_file.py", line 31, in scan_bytecode_loads
scan_bytecode_loads(names, c)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/wiggly/Desktop/twitterBot/venv/lib/python3.11/site-packages/py2app/recipes/detect_dunder_file.py", line 25, in scan_bytecode_loads
name = co.co_names[inst.arg]
~~~~~~~~~~~^^^^^^^^^^
IndexError: tuple index out of range
I use the default setup.py using the command provided in the docs py2applet --make-setup bot.py
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ["bot.py"]
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={"py2app": OPTIONS},
setup_requires=["py2app"],
)

The problem is that you have installed a beta version of Python (version 3.11). And looks like py2app version 0.28.2 is not compatible with it. Try to uninstall the 3.11 version and install the current release version 3.10 and it should work. Also, recreate the virtual environment after you install it because the current one would still be pointing to the 3.11 version.

Related

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

cx_freeze error "cx_Freeze.freezer.ConfigError: no base named Console"

I'm trying to convert a python 3.4 program of mine into an exe for distribution. I tried using cx_Freeze to do this. However, when I run python setup.py build with this setup.py:
from cx_Freeze import setup, Executable
setup( name = "Converter" ,
version = "0.1" ,
description = "" ,
executables = [Executable("filename.py")] , )
I get this error code:
C:\Python34>python setup.py build
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 6, in <module>
executables = [Executable("helloworld.py")] , )
File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "C:\Python34\lib\distutils\core.py", line 148, 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:\Python34\lib\distutils\command\build.py", line 126, in run
self.run_command(cmd_name)
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 231, in run
metadata = metadata)
File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 136, in __init__
self._VerifyConfiguration()
File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 504, in _VerifyConfiguration
self._GetBaseFileName()
File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 239, in _GetBaseFileName
raise ConfigError("no base named %s", name)
cx_Freeze.freezer.ConfigError: no base named Console
This same error code occurs when I try to setup for a hello world file. So it has nothing to do with my script.
Any help? This is the first time I've used cx_Freeze.
It appears that this line is failing argsSource.base = self._GetFileName("bases", name, ext) which means that it can't find that file, which makes sense. Check this folder C:\Python27\Lib\site-packages\cx_Freeze\bases for Console.exe. If you don't have that then try reinstalling cx_freeze. That's my directory for python. I would assume yours is in the same place but if not just search for it
Just type in cmd "pip uninstall cx_Freeze" for uninstall cx_Freeze and again reinstall it by type "pip install cx_Freeze".

Pycharm issues with installing Setuptools

I have recently played around with different versions of Python 2.7 and I ended up breaking PyCharm.
Firstly I have uninstalled and reinstalled Python and Pycharm multiple times with no luck.
I get the feeling that setup tools is the main issue but I can't seem to get it uninstalled correctly...
Below is the error Pycharm is giving and I am seeing similar errors trying to fix setuptools manually.
Anybody have a clue what is wrong with my environment?
Install package failed.
The following command was executed:
c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setup.py install
The error output of the command:
Traceback (most recent call last):
File "c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setup.py", line 204, in <module>
dist = setuptools.setup(**setup_params)
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:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setuptools\command\install.py", line 73, in run
self.do_egg_install()
File "c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setuptools\command\install.py", line 82, in do_egg_install
easy_install = self.distribution.get_command_class('easy_install')
File "c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setuptools\dist.py", line 363, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\pkg_resources.py", line 2108, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setuptools\command\easy_install.py", line 34, in <module>
from setuptools.sandbox import run_setup
File "c:\users\ask\appdata\local\temp\tmpf3zyjdpycharm-management\setuptools-1.1.5\setuptools\sandbox.py", line 209, in <module>
_EXCEPTIONS.append(GetGeneratePath())
File "win32com\client\gencache.pyc", line 131, in GetGeneratePath
AssertionError: Why do you want the genpath for a readonly store?
I finally managed to get this resolved. I installed a library called Automa about the same time I started getting the issue. With the install I had to add a PYTHONPATH entry and when I removed it today setup tools was able to install again.
I have added the PYTHONPATH back again and I am still able to install libraries with setupTools/Pip. So it must have not liked the path while installing.
I very happy to be back on track again!!!! :)

TypeError: dist must be a Distribution instance

My package depends on BeautifulSoup. If I install my package in a fresh virtualenv via python setup.py develop, I get the following error. If I execute python setup.py develop a second time, everything seems to work fine. I have no idea, what's happening. How to fix it to get a reproducable setup?
Best match: beautifulsoup4 4.3.2
Downloading https://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.3.2.tar.gz#md5=b8d157a204d56512a4cc196e53e7d8ee
Processing beautifulsoup4-4.3.2.tar.gz
Writing /tmp/easy_install-1eBfi3/beautifulsoup4-4.3.2/setup.cfg
Running beautifulsoup4-4.3.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-1eBfi3/beautifulsoup4-4.3.2/egg-dist-tmp-YmoFSq
Traceback (most recent call last):
File "setup.py", line 73, in <module>
""",
File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 27, in run
self.install_for_development()
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 129, in install_for_development
self.process_distribution(None, self.dist, not self.no_deps)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 671, in process_distribution
[requirement], self.local_index, self.easy_install
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/pkg_resources.py", line 564, in resolve
dist = best[req.key] = env.best_match(req, self, installer)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/pkg_resources.py", line 802, in best_match
return self.obtain(req, installer) # try and download/install
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/pkg_resources.py", line 814, in obtain
return installer(requirement)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 593, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 623, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 809, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1015, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1000, in run_setup
run_setup(setup_script, args)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 50, in run_setup
lambda: execfile(
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 100, in run
return func()
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 52, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 27, in <module>
'raven',
File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 970, in run_command
cmd_obj = self.get_command_obj(command)
File "/usr/lib/python2.7/distutils/dist.py", line 846, in get_command_obj
cmd_obj = self.command_obj[command] = klass(self)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/__init__.py", line 69, in __init__
_Command.__init__(self,dist)
File "/usr/lib/python2.7/distutils/cmd.py", line 59, in __init__
raise TypeError, "dist must be a Distribution instance"
TypeError: dist must be a Distribution instance
This error has to do with a discrepancy between the versions of distutils and setuptools installed on your machine. Upgrading setuptools to the current version is likely to resolve the issue.
EDIT: This solution no longer works for me (and apparently never worked for Jens -- see comment below). What now works for me is to import setuptools before anything else in whatever script I'm calling that leads to this error.
This error is discussed in many issues on GitHub, in many packages, but I find this discussion to be the most informative.
The only way I was able to solve it was to follow the https://bugs.python.org/file37554/distutils_accomodate_distribution_ducktypes.patch
So - I removed /usr/lib/python2.7/distutils/cmd.py and /usr/lib/python2.7/distutils/cmd.pyc ( ran a python setup.py develop - just to make sure it fails and is not using the pyc from somewhere else ) and then recreated /usr/lib/python2.7/distutils/cmd.py - only this time with the changes as shown in the patch. Then when I used python setup.py again - it worked..
install dnspython. pip install dnspython. Or check if u have older version of dnspython and upgrade
Try using pip for installing your package
$ pip install -e path/to/your/Project
See http://pip.readthedocs.org/en/latest/reference/pip_install.html#editable-installs for more information.
When I encountered this, it appeared at first glance that it was complaining that Distribution() didn't produce a Distribution instance, but that was only partly true.
setuptools provides its own Distribution, and monkeypatches it into distutils. That works in most cases, but will fail if you get a reference to Distribution before setuptools has been imported and done its magic.
The top of the script read:
from distutils.dist import Distribution
and then later we were importing and using various parts of setuptools.
The solution in my case was to do a late import in the function that uses it so Distribution was obtained after setuptools was loaded.

No initscrip name console - CX_freeze

I have been trying to get cx_freeze working on ubuntu, but when i try to run the "python setup.py build" i get the following error:
cx_Freeze.freezer.ConfigError: no initscript named Console
I have searched google and i see a lot of people have ahd this issue, but i can't seem to find a solution.
my setup.py code is as follows:
from cx_Freeze import setup, Executable
setup( name = "hello world" ,
version = "0.1" ,
description = "Hello" ,
executables = [Executable("hello.py")] ,
)
I have placed the setup.py file and hello.py in the same folder.
Any idea as to what could solve this problem?
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 7, in <module>
executables = [Executable("hello.py")] ,
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
cx_Freeze/dist.py", line 365, in setup
distutils.core.setup(**attrs)
File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run
self.run_command(cmd_name)
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/dist.py", line 234, in run
metadata = metadata)
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/freezer.py", line 104, in __init__
self._VerifyConfiguration()
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/freezer.py", line 466, in _VerifyConfiguration
self._GetInitScriptFileName()
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/freezer.py", line 311, in _GetInitScriptFileName
raise ConfigError("no initscript named %s", name)
cx_Freeze.freezer.ConfigError: no initscript named Console
For my installation I took same problem. Looks like symbolic link for initscripts not created, so I make it manually and everything works (change cx_Freeze version to your own):
cd /usr/local/lib/python2.7/dist-packages/
cd cx_Freeze-4.3.1-py2.7-linux-i686.egg
sudo ln -s -t cx_Freeze/ ../../cx_Freeze/initscripts/
PS: Ubuntu 12.10/quantal, Python 2.7.3

Categories