0

I am trying to create a simple python executable program - Hello World by following this link https://mborgerson.com/creating-an-executable-from-a-python-script.

The steps I took is first I create a python program, example: print("Hello, World!") I save this py program file into python script

C:\Users\d\AppData\Local\Programs\Python\Python35-32\Scripts

Then I install PyInstaller by going to command line point to directory python script and type

pip install PyInstaller

. After this, in command line I type

pyinstaller.exe --onefile --windowed helloWORLD.py

after putting the helloWORLD py program in the script folder. What happen after that is that it creates a

helloWORLD.exe

in script dist directory. However I can't run it. In vb.net I can run an executable program by double clicking on it. The second question, after being able to create the python executable program and run it; how do I create an icon for the python executable program. Thanks !

Johnseito
  • 315
  • 1
  • 9
  • 24
  • first run it in console/terminal/cmd.exe to see if you don't have error message. – furas Dec 25 '16 at 05:14
  • read `PyInstalller` doc how to add elements to program. It creates config file `helloWORLD.spec`. Or at least run `pyinstaller --help` – furas Dec 25 '16 at 05:16
  • furas, thanks for your advice and suggestion. It looks like I got it resolved. I put my python program into a directory, it can be any directory. Then I go to command prompt and point it to the saved directory then type **pyinstaller programNAME.py**. After this command, the prompt created a bunch of files and directories; spec, build, dist, and in dist there lies the python executable program that can be run by just clicking on it. However, I was wondering what you mean by run it in console/terminal/cmd.exe to test, and how about creating the icon. I am new to this,Thanks – Johnseito Dec 25 '16 at 06:05
  • run `cmd.exe` or `powershell`, go to folder with script (using cmd.exe/powershell) and write `python your_script.py` to run it. And it will print all errors in this `cmd.exe/powershell` window and it will not close it so you can see it. When you run by clicking icon then it uses `cmd.exe` to run and display error but it close `cmd.exe` so fast that you can't see it (and any `input()` or `raw_input()` in code can't stop it) – furas Dec 25 '16 at 18:16
  • if you see `pyinstaller --help` there is option `-i filename.ico` or `--icon filename.ico`. You can also add icon into `helloWORLD.spec` file because `pyinstaller` use this inforamtion when you run `pyinstaller.exe --onefile --windowed helloWORLD.py`. – furas Dec 25 '16 at 18:19
  • furas, thanks for the awesome and detail information. I understand your first point, run the program in command prompt, I did just that and I see no error message. However I am confused with the line pyinstaller.exe --onefile --windowed helloWORLD.py because I think pyinstaller programNAME.py is better. It gives you an .exe executable file in dist directory. Was wondering if your command pyinstaller.exe --onefile --windowed helloWORLD.py gives icon to the program which is what I wanted to do. Thanks – Johnseito Dec 26 '16 at 02:22
  • Also I noticed - I created another program, I run it in command prompt pyinstaller programName.py to produce spec file, dist, build, and pycache directory. In the dist directory there is the program in exe (executable) file. I click on it, it appears and disappear so quickly, however it didn't show any result, it should have produce an excel file in the directory it runs in. Then I went to command prompt, and typed python programNAME.py and it works, it produced the excel file in the directory. I wonder why can't I click on the executable file to do the same thing ? – Johnseito Dec 26 '16 at 02:23

0 Answers0