Python files packaged as *.exe files (single files and multiple files)

Source: Internet
Author: User

Environment: WIN10 64-bit python3.7

Single *.py file packaging
Python GUI: program packaged as EXE

First, install Pyinstaller, command pip install Pyinstaller, (uppercase P, knocking on the blackboard, to test)
Second, packaging EXE steps:

CMD enters the PY program project directory, executes the command: Pyinstaller-f-w--icon=xxx.ico main.py--noconsole. Where-F is the generation of a single EXE executable file, and-W represents the form program,
--icon is to set the EXE's display icon, ' main.py ' is the program's entry,--noconsole means not to show the cmd window, in turn to see the cmd window to change to--console. *.ico files can be processed on the online ICO vector Chart conversion Tool
http://www.faviconico.org/

After a brush screen, finally hit the successful prompt:

There are a few more folders in the program directory: A spec file, a build folder, a Dist folder, where the Dist folder is the EXE application we generated:


FATAL ERROR:
Implementation, you should be able to see the program interface, but ... The pop-up was an error box: Failed to execute script pyi_rth_qt5plugins

The reason for this error is that Pyinstaller can not find the PYQT library, installed through the online packaged PYQT installer package, this problem will not occur, and we are installed through PIP,
The path to the PYQT is not added to the environment variable.
The workaround is to add the paths parameter to the package command: Pyinstaller--paths c:users ... Python35-32/lib/site-packages/pyqt5/qt/bin-f-W--icon=roman.ico main.py or SET environment variable. At this time, look at the generated EXE, the file size has been increased from 8.5M to 14.5M, again, OK, see our interface, and the function is OK,

Multi-File Packaging:

Multi-file Packaging reference: 80964272

The command format is as follows, and the following command is a command for the convenient display of the branch processing:

Pyinstaller [main file]-p [other file 1]-p [other file 2]
--hidden-import [self-built module 1]
--hidden-import [self-built Module 2]
# above is an entire command
Pyinstaller main.py-p mysql.py-p other.py--hidden-import MySQL--hidden-import other

The generated main.exe can be found under the directory structure: "Program root \dist\main\". Run a copy of the other dependent files into the program root \dist\main\


Project XXX example, Main and ICO file to put together the-P folder, because under the project I created the case, autodriver, data, page folder, folder inside the *.py file through--hiddent-import Point, the code is as follows:
Pyinstaller-f-I t.ico-w main.py-p case-p autodriver-p data-p page-p page--hidden-import workday.py--hidden-impor T auto_driver.py--hidden-import login.csv--hidden-import base_page.py--hiddent-import sub_page.py
Note:--hiddent-import is connected, dist folder inside to copy the required questionnaires, and then the entire Dist folder can be moved to another location, then run the *.exe file can execute the program

Python files packaged as *.exe files (single files and multiple files)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.