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