How to build your own Python code to EXE file - WPC-Systems-Ltd/WPC_Python_driver_release GitHub Wiki

Step 1: Take Example_analog_input_on_demand for example

There are Material, UI_design folders and main.py file in Example_analog_input_on_demand folder.

  • UI_design folder contains .ui file.

  • Material folder contains images and so on.

Example_analog_input_on_demand 
├── Material
│   ├── WPC_Led_blue.png
│   ├── WPC_Led_gray.png
│   ├── WPC_Led_green.png
│   ├── WPC_Led_red.png
│   ├── WPC_switch_blue.png
│   ├── WPC_switch_gray.png
│   ├── WPC_trademark.jpg
├── UI_design
│   ├── example_GUI_AI_on_demand.ui
│   ├── Ui_example_GUI_AI_on_demand.py
├── main.py

:warning: Do not change the Material folder name and put any subfolders in it, unless you know what you're doing.

Step 2: Open a command window, and navigate to the directory where your .py file is located

Step 3: Build EXE file with wpcEXEbuilder

$ wpcEXEbuilder your_program.py 

We generated our main.spec file by using wpcEXEbuilder main.py.

Step 4: What we generate in it

In the current directory, a bunch of new folders will be made. Here's what to do with them:

  • Your executable file will be in folder "dist", and will be called main.exe.

  • The folder "build" is unnecessary.

  • Also, the file main.spec will be created.

Example_analog_input_on_demand 
├── build
│   ├── ...
│   ├── ...
├── dist
│   ├── main.exe
├── Material
│   ├── WPC_Led_blue.png
│   ├── WPC_Led_gray.png
│   ├── WPC_Led_green.png
│   ├── WPC_Led_red.png
│   ├── WPC_switch_blue.png
│   ├── WPC_switch_gray.png
│   ├── WPC_trademark.jpg
├── UI_design
│   ├── example_GUI_AI_on_demand.ui
│   ├── Ui_example_GUI_AI_on_demand.py
├── main.py
├── main.spec

Step 5: You will get executable file main.exe in dist folder

Double click main.exe

It will show like that

Step 6: Change some arguments inside the main.spec file

If you want to modify something such as adding icon or picture, you can edit .spec file directly then use following command:

If you modify your main.py code, also use following command:

$ pyinstaller main.spec