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

What are the eight steps in the practical application of Pythonexe

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Pythonexe practical application of the eight steps, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Practical steps

Note: suppose python is installed in the c:\ python25 directory, and the executable files of * are placed in the d:\ dist directory

1. First go to the c:\ python25\ Lib directory and copy all the files, such as to the d:\ pythonlib directory

two。 Open a cmd window, go to the d:\ pythonlib directory, and run python-OO compileall.py-f. Compile all the .py files in lib into .pyo files.

3. Delete all .py and .pyc files in the d:\ pythonlib directory, because we only need .pyo files to get these libraries running.

4. Delete all unused files in the directory, such as curses,test,idlelib,msilib, etc., to reduce the size of the generated files.

5. Package these libraries into a zip file, such as stdlib.zip, and put them in the d:\ dist directory

6. Copy the .pyd and .dll files in the c:\ python25\ dlls directory to the d:\ dist\ dlls directory, of course, delete some files that are impossible to use, such as _ msi.pyd,_ssl.pyd, etc., you can reduce the size of the files.

7. Pack the program you wrote into a mysrc.zip package as described in steps 2 to 5, and put it in the d:\ dist directory. Note: the entry of the self-written program should be the main.pyo file.

8. Use the following C program to compile an executable file, such as runpy.exe, and put it in d:\ dist.

# include # include int main () {

Get the directory where the current executable file is located

Char szPath [10240]; char szCmd [10240]; GetModuleFileName (NULL, szPath, sizeof (szPath)); char* p = strrchr (szPath,'\\'); if (p = = NULL) {printf ("Get module file name error!\ n"); return-1;} * p = 0

Set the runtime PATH

Sprintf (szCmd, "PATH=%s\\ dlls;%%PATH%%", szPath); _ putenv (szCmd)

Set sys.path to ['.', 'own source code zip file', 'standard library zip file', 'dll directory']

Then call the main module

Sprintf (szCmd, "import sys\ n"sys.path= ['.', ringing% s\\ mysrc.zip', ringing% s\\ stdlib.zip', ringing% s\\ dlls']\ n" import main\ n ", szPath, szPath, szPath); Py_OptimizeFlag = 2; Py_NoSiteFlag = 1; Py_Initialize (); PyRun_SimpleString (szCmd); return 0; is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, 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

Development

Wechat

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

12
Report