2

When I use this command on my python code file in windows 10 bash shell:

 pyinstaller Test.py

It produces these files (and some others):

enter image description here

I'm not sure if the produced file is an .exe file and will work. I cannot run it. Could you please help? Thanks.

6
  • Are you running on linux or windows? If you're running on linux I guess this would do: chmod +x Test and then .\Test
    – Anteino
    Commented Dec 17, 2019 at 0:48
  • You can try to run it in cmd so you can get the output while excuting it. The program may encounter errors and exited while you could not notice.
    – ToughMind
    Commented Dec 17, 2019 at 0:54
  • Thanks for your comments. I need an .exe file, upon clicking on which it runs the program. This is specifically to facilitate the process for beginner people in the company. They are not expert to open shell and run! Suggestions are appreciated.
    – mah65
    Commented Dec 17, 2019 at 1:02
  • yes but if you run your exe from cmd then you will probably see an error message that will tell you what went wrong
    – user5386938
    Commented Dec 17, 2019 at 1:40
  • I'm not sure if it is an exe file. The problem is big!
    – mah65
    Commented Dec 17, 2019 at 1:46

1 Answer 1

2

As I see your screenshot you have tried to run the pyinstaller on Linux OS because the generated *.so files are Linux specified shared objects. Furthermore the Test file is a Linux specified executable without extension.

If you want to create an EXE file from your Python file/project, you have to run the pyintaller on a Windows OS. The pyinstaller will collect all needed files Eg.: DLLs, SDKs, etc...

I have copied the below section from PyInstaller official documentation:

PyInstaller is tested against Windows, Mac OS X, and Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a Linux app you run it in Linux, etc. PyInstaller has been used successfully with AIX, Solaris, and FreeBSD, but is not tested against them.

Some hints how you can create a working EXE file from your Python file/project.

Use the --onefile or -F flag:

"In one-file mode, there is no call to COLLECT, and the EXE instance receives all of the scripts, modules and binaries." Eg.: pyinstaller --onefile test.py

Use the --windowed or -w flag:

Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems.

Use the --clean flag:

Clean PyInstaller cache and remove temporary files before building.

My recommended command:

pyinstaller -Fw --clean test.py

You should run the above command on Windows OS.

FYI:

If you have a complex Python project and you have dependencies (required files, folder structure etc...) I recommended to use a *.spec file. You can read the detail about it on the following link: https://pythonhosted.org/PyInstaller/spec-files.html

4
  • Thanks for your help. Appreciate your time. Pyinstaller can be run in Windows Bash Shell. However, it does not run in CMD, because I receive this error: "'pyinstaller' is not recognized as an internal or external command, operable program or batch file.". This is strange, because I have installed it already using "pip install pyinstaller". Maybe the paths are not set correctly?!
    – mah65
    Commented Dec 19, 2019 at 23:59
  • 1
    You are right. Probably the path of the PyInstaller is not found. First of all is your are using Python3, you should try the following command to install PyInstaller: pip3 install pyinstaller. Furthermore you should set your PATH environment variable to find the PyInstaller executable like in this answer: stackoverflow.com/a/45952113/11502612 . Other solution to call the PyInstaller directly like in this answer: stackoverflow.com/a/40117620/11502612 . If both of solutions are not working, I recommended to do it in a Python virtual environment. Commented Dec 20, 2019 at 11:08
  • A post about PyInstaller in Python virtual environment: stackoverflow.com/questions/48629486/… Commented Dec 20, 2019 at 11:09
  • This link really helped when using anaconda python. stackoverflow.com/questions/45951964/….......... Also, my final solution: stackoverflow.com/questions/59524507/…
    – mah65
    Commented Dec 31, 2019 at 1:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.