13

I am trying to convert a .py file to an exe. My file, hello.py, reads:

print "Hello, World!"

I am currently trying to use pyinstaller. However when I run the command

pyinstaller hello.py

I get the error message "tuple index out of range" which I have been told means my version of python is unsupported. In particular it would seem the situation is that pyinstaller thinks I am trying to compile python 3.6 code into an exe. But I have python 2.7 and python 3.6 installed. How do I let it know that I want it to regard the code as python 2.7 code?

Kyle Sargent
  • 151
  • 1
  • 1
  • 5
  • There might be a better response from the PyInstaller support mechanisms. http://www.pyinstaller.org/support.html – lit Apr 16 '17 at 23:50

6 Answers6

29

Using Python3:

Make sure PyInstaller is installed in Python 3.x: pip3 freeze

PyInstaller==3.3.1

Then running the command:

/path/to/python3 -m PyInstaller your_script.py
Joseph D.
  • 11,804
  • 3
  • 34
  • 67
  • 7
    Note that on Windows at least (I haven't tested elsewhere yet) the module name is case-sensitive (uppercase 'P' and 'I'). Also on Windows, using the python launcher that comes with Python3 is handy: e.g., `py -3.6-32 -m PyInstaller script.py`. – dhobbs Aug 15 '18 at 18:35
5

First install Pyinstaller in your python2.7 version if not installed previously py -2 -m pip install pyinstaller

and then go to your folder and

py -2 -m pyinstaller -F filename.py
2

The answers have devolved in "How do I tell pyinstaller which python version to use?" So, I know that this doesn't really answer the original question. However, I wasted about an hour trying to figure this out so, in the hopes that others don't have to waste an hour... To force pyinstaller to use Python 3.9 under Windows do the following.

Given Windows and Python 3.9:

python3.9 -m PyInstaller [whatever options you want]

You have to type it as PyInstaller instead of pyinstaller (i.e. note the capitalization).

python3.9 -m pyinstaller

Produces an error:

C:\Users\chris.SR\AppData\Local\Programs\Python\Python39\python.exe: No module named pyinstaller
shrewmouse
  • 5,338
  • 3
  • 38
  • 43
1

Supposing you have python 2.x on the path under python2 you can do

    python2 -m pyinstaller hello.py
matusko
  • 3,487
  • 3
  • 20
  • 31
1

When you need to bundle your application within one OS but for different versions of Python and support libraries – for example, a Python 3 version and a Python 2.7 version; or a supported version that uses Qt4 and a development version that uses Qt5 – we recommend you use virtualenv. With virtualenv you can maintain different combinations of Python and installed packages, and switch from one combination to another easily. (If you work only with Python 3.4 and later, python3 -m venv does the same job, see module venv.)

  • Use virtualenv to create as many different development environments as you need, each
  • with its unique combination of Python and installed packages.
  • Install PyInstaller in each environment.
  • Use PyInstaller to build your application in each environment.
0

I ran two a couple things. If you uninstall python3, it works with python2. If you have python3 installed (and it is the primary), and have pyinstaller installed in python3, it wont work (python3 pyinstaller used). If you have python3 installed, but do not have it installed in python3 or uninstalled it (pip3 uninstall pyinstaller), pyinstaller works.

Checking the environmental variables (windows 10) PATH had python3 first. This may be the issue and may not be resolved because it is checking python3 directories first, and picks up pyinstaller for python3. pyinstaller does not check the file either (#!/usr/env/bin python2).

Unless pyinstaller puts an option relating to this issue, there may be no solution short of uninstalling pyinstaller from python3 temporarily.

note could also use py2exe, using py2exe for python2, pyinstaller for python3