Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to compile a py file to an exe file

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use Python to compile py files into exe files. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The premise is that the Python environment is already installed.

Step 1: download and install the pyinstalle library in PyCharm or install it using CMD

Install in PyCharm: File- > Settings- > Project Interpreter- > add the appropriate package

Or use CMD to install, prompting you to install pyinstaller successfully.

Pip install pyinstaller

Step 2: enter the folder where pyinstaller .exe is located and enter CMD

Step 3: compile the .py file that needs to be packaged into a .exe executable file.

Pyinstaller-w-F bingdundun.py

(- w means to cancel the dos window)

Enter and enter, and the final prompt is successful

Finally, go back to PyCharm and type the relevant commands into a .exe file.

Pyinstaller-F * .pypyinstaller-F-w * .py

(- w means to cancel the dos window)

Pyinstaller-F-w-icon=p.ico bingdundun.py

(- icon=p.ico, p.ico is the file name of the icon, which is the same save path as the [dist] directory)

The parameters related to the command are as follows:

Icon= icon path (pyinstaller-F-icon=my.ico XXXX.py)

Step 4: go to the folder where pyinstaller.exe is located, find the dist folder, open it to view the generated executable exe file, and double-click to open the preview program.

Expansion

If you prompt "pyinstaller is not an internal or external command..." when pycharm installs the pyinstaller library to generate a .exe file.

The reason for the error: the pyinstaller.exe file is not in the Scripts file in the default path when installing the python interpreter, but somewhere else.

Solution: copy the pyinstaller.exe file to the Scripts file under the default path address of the installation Python interpreter.

View the location of the interpreter directory

Finally, if you are still prompted to report an error, check the configured environment variables to see if there is a problem with the configuration.

On "how to use Python to compile py files into exe files" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report