0

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?

Halona
  • 1,475
  • 1
  • 15
  • 26
  • 1
    According to [pypi](https://pypi.org/project/py2exe/#data) py2exe seems to only support up to Python 3.4. – Michael Butscher Jul 23 '20 at 16:48
  • Michael, do you know what other way I can I compile python script? (that is supported) – Halona Jul 23 '20 at 16:51
  • @Halona https://stackoverflow.com/q/5458048/7976758, https://stackoverflow.com/search?q=%5Bpython%5D+standalone+script – phd Jul 23 '20 at 18:32

1 Answers1

0

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/

eviluser
  • 14
  • 1