Search code examples
python-3.xexepyinstallerpyserial

Can't get .exe to execute on other machine - "No module named serial" error


System: Python 3.7 64x running on Windows 10. I also have Anaconda installed on my machine and I program through VS Code. All modules have been installed, verified installed, and are up-to-date.

I have written a script and compiled it into an .exe using pyinstaller. pyinstaller -wFi pyico.ico endpointapp3.py.The .exe works and runs on my machine but it's not meant for my computer. Previous iterations of this script have been compiled, tested, and worked appropriately on its destination computer, a Windows 7 machine with no python installed.

My latest version now includes pyserial, and works, again, on my machine, but I after compiling and creating an .exe file for the destination machine I encounter this error.

File "endpointapp2.py", line 9 in <module> 
ModuleNotFoundError: No module named 'serial' 
[3512] Failed to execute script endpointapp2.py

Line 9 is my import serial line

As I mentioned before, this executable runs on my machine, but not on the destination machine it was designed for. I don't want to install python, or python modules on the destination machine because I want the .exe to be all inclusive.

Questions:

  1. Why am I getting this error? What does it mean?
  2. Is there a work around that allows me to compile everything together (using pyinstaller) that will hold all the necessary module information within the .exe?
  3. Is there something else I should be adding to my original script that will allow me to work through this?

NOT A DUPLICATE - This post is for compiling and running python .exe's on another machine, independent of python, with no modules or python installed.


Solution

  • With some assistance and helpful advice (thanks martineau) I was able to solve my problem. When compiling with pyinstaller, it makes a .spec file that it actually uses to compile to .exe.

    Here I found the necessary steps to make sure I was adding the files I needed for pyinstaller.

    Here I found out how to properly add the module information into my compiling code.

    Once pyinstaller had the correct info in the .spec file I was able to compile and execute on the destination machine as intended.