Configure the Python runtime environment in Windows, which is only 700KB

Source: Internet
Author: User

Next we can quickly configure the Python runtime environment with a super small kb Python package. The following section will introduce the specific operation process.

Python on Windows has not been compiled before. Generally, py2exe and pyinstaller are used for packaging and publishing, and the generated file must be at least 3 MB. In addition, Python only has VS Project files. That is to say, if you want to compile with GCC, you need to write or modify the Makefile yourself. After Mingw32 is installed on Debian, modify the default Makefile to make it support compiling to the Windows version. The source code has been greatly changed, so the process will not be written here, I also forgot how many changes I made. For the compilation method, refer to my previous blog. It is recommended that VS developers easily compile VS instead of making so many changes.

 

 

The figure shows the compiled Python environment that runs the previously written Sogou proxy script. This time I used the Python2.3 version. After the compiled file is compressed with UPX, the size is quite small. Comparison:

Python2.3 (Windows): without the library 412KB, with the basic standard library 695KB
Python2.6 (Linux): without the database 1.3 kb, with the basic standard library MB
Python3.3 (Linux): 1 MB Without libraries and 2.1 MB with basic standard Libraries

This time, python of Windows compiled the following built-in modules:

 

The standard library files are packaged into libpy. dll. This is not a dynamic link library file, but a zip package containing pyc compiled by the standard library.

 

The compiled python.exeis also renamed as runapp.exe. In addition, the default parameter is not an interactive shell. If you want to interact, you can add a parameter, such as-v.

If no parameter exists by default, the pyc file (Compiled py) named main. app under the current directory will be called ).

All these modifications are made to deploy and embed the Python runtime environment into other applications. It should be noted that, after all, it is not a complete environment, so some features such as the standard library of SSL and emails are not included. I like urllib and SimpleHTTPServer. If not, you can package it into libpy. dll.

Related Article

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.