2

I am currently making a physics simulation using VPython, and want to turn it into an exe file, using pyinstaller, so that it can run on a Mac laptop.

Essentially, I have two questions - one short and one long.

Short question: will the exe file I create using pyinstaller run on a Mac laptop if I created it using windows?

Long question: I converted my program into an exe, but it doesn't work. Here is a screen shot of the error: Pyinstaller error

Good news: I think I have found a solution to my problem from another question on stackoverflow, but I am a newbie and can't comprehend a single word of the answer. And, the answer uses anaconda, but I am using pycharm... in other words I am completely lost.

Link to answer: how to make vpython .exe using pyinstaller

Momo 6aye3
  • 95
  • 1
  • 7

2 Answers2

0

In order to convert a Python program into an executable file (i.e. “freeze” the program), you’ll need something like PyInstaller. PyInstaller and related projects (such as py2exe) take Python programs, and package them into *.exe files for your users to run. The end result is a standalone executable file that doesn’t require Python to be installed on the end user’s system.

Keep in mind though, that these methods of “freezing” a Python program can incur a fairly large startup penalty and/or bloat your executable size. The end result is an executable that may take a significantly longer time to start up than usual, and may be much larger than you would expect it to be.

JDOE
  • 43
  • 5
  • Thanks for the heads up! But in the end, I definitely need to change my program to an executable, so I have no choice. Do you have any idea how can I do that in my situation (described above)? – Momo 6aye3 Dec 28 '17 at 16:40
0

This took a few steps to get it to work for me, hopefully they'll also work for you.

Step 1: The first problem is that vpython requires the files in the vpython/vpython_libraries directory to work, and it's looking for them, but pyinstaller doesn't include them by default, hence the PathNotFoundError. What you need to do is add those files by specifying the add-data option for pyinstaller: pyinstaller my_program.py --add-data "path/to/vpython"

Step 2: You now run into another error: ImportError: cannot import name '__version__' from partially initialized module 'vpython' This requires you to actually go in and change the python code in the vpython package, before you run pyinstaller. Go into the __init__.py file in the vpython directory (wherever you installed it) and you will see the following lines at lines 5-9 of the file:

try:
    __version__ = get_distribution(__name__).version
except DistributionNotFound:
    # package is not installed
    pass

Change the pass statement to __version__ = "", so the result looks like this:

try:
        __version__ = get_distribution(__name__).version
    except DistributionNotFound:
        # package is not installed
        __version__ = ""

Step 3: After compilation, you run it and then get a series of FileNotFoundError Error messages. The first one for me was FileNotFoundError: [Errno 2] No such file or directory: 'a\long\path\to\vpython\vpython_libraries\glowcomm.htmlc' If you look carefully in the vpython_libraries there is a glowcomm.html file, but it is not .htmlc. Change the file extension to .htmlc.

You will then get more messages saying things like FileNotFoundError: [Errno 2] No such file or directory: 'long\path\to\vpython\vpython_librariesc\ide.css'. Notice how vpython_librariesc has a c at the end. Duplicate the vpython_libraries folder, and name the duplicate vpython_librariesc (Just renaming vpython_libraries doesn't work). You will then get the same error, but saying the problem is vpython_datac. Do the same thing that you did for vpython_libraries.

That did it for me, but if you get more problems saying files don't exist, just try copying and changing the directories to be what you're looking for, or changing the file extension