In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What is the actual operation procedure of Pythonexe? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Python6. Copying the .pyd and .dll files in the c:\ python25\ dlls directory to the d:\ dist\ dlls directory does not have a built-in function to compile to exe. It brings a lot of trouble to the deployment of python programs. So there are some nice tools like py2exe that automatically compile .py files into .exe files. Recently, I took the time to study the dynamic implementation of functions similar to py2exe, hoping to enhance the understanding of python. It turned out pretty good. Record the results and share them with you.
Principle
The method described in this paper is based on the following functions of python
1. When the python program runs, it looks for the library file in the path specified by sys.path.
2. Python starts from 2.3.It supports import libraries from zip files (.py, .pyc and .pyo, but not .pyd)
3. Python provides C API, so that programs in c language can easily call python programs.
Practical steps
Note: suppose Pythonexe 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 .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
Of course, deleting some files that are impossible to use, such as msi.pyd,_ssl.pyd, can reduce the size of the file.
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
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 sys.path to ['.', 'own source code zip file', 'standard library zip file', 'dll directory']
Then call the main module
Put python25.dll into the d:\ dist directory to complete part of the manual pythonexe executable program.
After reading the above, have you mastered the actual operation steps of Pythonexe? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.