Eight Steps for Pythonexe Application

Source: Internet
Author: User

During the actual use of Pythonexe, many people may be puzzled by the actual operation steps. The following article describes the steps of Pythonexe in detail, the following is the detailed content of the article. If you are interested in it, you will find some benefits.

Procedure

Note: Assume that python is installed in the c: \ python25 directory, and the final executable file is placed in the d: \ dist directory.
1. Go to the c: \ python25 \ Lib directory and copy all the files, for example, to the d: \ pythonlib directory.
2. Open a cmd window, go to the d: \ pythonlib directory, and run python-OO compileall. py-f. Compile the. py file in lib into the. pyo file.

  • Introduction to common Python modules
  • Procedure
  • How to speed up Python string SEARCH
  • Application Cases of Python map ease-of-use techniques
  • How can I evaluate Python default parameters?

3. Delete all. py and. pyc files in the d: \ pythonlib directory, because we can run these libraries as long as there is a. pyo file.
4. Delete all unnecessary files in the directory, such as curses, test, idlelib, and msilib, to reduce the volume of generated files.

5. Pack these databases into a zip file, such as stdlib.zip, and put them in the d: \ dist directory.
6. in the c: \ python25 \ dlls directory. pyd and. dll file, copied to the d: \ dist \ dlls directory, of course, delete some files that are not available _ msi. pyd, _ ssl. pyd and so on can reduce the file volume

7. Compile the program written in step 2 to Step 5 into a mysrc.zip package and put it in the d: \ dist directory. Note: the entry to the self-written program should be the main. pyo file.
8. Compile an executable file using the C program, and call runpy.exe, which is also stored in d: \ dist.

 
 
  1. #include <Python.h>   
  2. #include <Windows.h>   
  3. #include <stdlib.h>   
  4. #include <stdio.h>   
  5.  
  6. int main()   
  7. {   

Obtain the directory of the current executable file.

 
 
  1. char szPath[10240];   
  2. char szCmd[10240];   
  3. GetModuleFileName(NULL, szPath, sizeof(szPath));   
  4. char* p = strrchr(szPath, '\\');   
  5. if (p == NULL)   
  6. {   
  7. printf("Get module file name error!\n");   
  8. return -1;   
  9. }   
  10.  
  11. *p = 0;   
  12.  

Set the PATH at runtime

 
 
  1. sprintf(szCmd, "PATH=%s\\dlls;%%PATH%%", szPath);   
  2. _putenv(szCmd);   
  3.  

Set sys. path to ['.', 'Your source code zip file', 'standard library zip file', 'dll directory']
Then call the main module

 
 
  1. sprintf(szCmd,   
  2. "import sys\n"   
  3. "sys.path=['.', r'%s\\mysrc.zip', r'%s\\stdlib.zip', r'%s\\dlls']\n"   
  4. "import main\n",   
  5. szPath, szPath, szPath);   
  6.  
  7. Py_OptimizeFlag = 2;   
  8. Py_NoSiteFlag = 1;   
  9. Py_Initialize();   
  10. PyRun_SimpleString(szCmd);   
  11. return 0;   
  12. }   

The above describes the actual steps for manual Pythonexe executable programs.

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.