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 package python files into .exe executable programs by py2exe

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Today, I will talk to you about how py2exe realizes the packaging of python files into .exe executable programs, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Use py2exe to package python programs into .exe executable programs (users who do not have the python runtime environment installed can also run this program to achieve remote email control device shutdown and restart)

Py2exe is a python program packaging tool, download address: https://sourceforge.net/projects/py2exe/files/, select the matching python version, and the number of bits on the computer, as shown in the third screenshot

Second, install after the download is completed, do not allow to modify the installation directory, and finally install to the py2exe folder under C:\ Python27\ Lib\ site-packages

3. Packaging steps:

1. In python compiler, write a .py file as required for python packaging program: [install bootstrap python program], set the installation bootstrap python program name to: email_package.py, and the python program to be packaged is: sendEmail.py [see tweet: py2exe implementation python file packaged as .exe executable program (part I)]

2. The contents of email_package.py file are as follows:

Note:

(1) Chinese cannot appear in the content of the document

(2), email_package.py and sendEmail.py files must be placed in: C:\ Python27 directory

3. Execute the corresponding packaging command in the cmd command window:

(1) first go to: C:\ Python27 directory and enter the command: python email_package.py py2exe

If there is no error prompt, it means that the program is packaged successfully.

(2) check the packaged sendEmail.py program

In the directory C:\ Python27\ dist, you can view the sendEmail.exe executable (packaged programs)

Double-click to execute the program, and the running status is shown in the screenshot below:

4. After starting the sendEmail.exe program above, send an email titled shutdown or restart to Sina mailbox, that is, tweet: "py2exe implements python file packaged as .exe executable program" def readMail (self): the mailbox logged in the method.

The program will automatically read the latest email in the mailbox every 2 seconds. If the title of the email is shutdown or restart, it will correspondingly perform the shutdown and restart of the physical machine running the .exe program, otherwise: the .exe program will not do anything. After dormant for 2 seconds, scan the mailbox again to read the latest email and cycle.

Note: this program can run normally on windows computer, but Mac computer did not pass the test.

After reading the above, do you have any further understanding of how py2exe can package python files into .exe executable programs? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Internet Technology

Wechat

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

12
Report