Export Python3 as EXE program

Source: Internet
Author: User
Tags python script

I. Pyinstaller INTRODUCTION

Python is a scripting language that is interpreted by the interpreter to execute. How it is published:

    • . py file: For open source projects or source code is not so important, directly provide the source code, users need to install Python itself and install a variety of dependent libraries. (This is the case with all the official Python installation packages)

    • . pyc file: Some companies or individuals because of confidential or various reasons, not willing to source code is seen by the runtime, you can use the PYc file publishing, PYc file is the Python interpreter can recognize the binary code, so after publishing is cross-platform, users need to install the corresponding version of Python and dependent library.

    • Executable file: For non-code farmers or some small white users, you let him to install a python and also toss a bunch of dependent libraries, it is a disaster. For this type of user, the simplest way is to provide an executable file, just tell TA to use it. The trouble is that you need to package different executables for different platforms (Windows,linux,mac,... )。

This article is mainly about the last way,. Py and. PYc are relatively simple, python itself can be done. There are several ways to package Python scripts into executables, and this article focuses on Pyinstaller,

Introduction to the principle of pyinstaller

Pyinstaller is actually the Python parser and your own scripts packaged into an executable file, and compiled into a real machine code is completely different, so do not expect to be packaged into an executable file will improve the efficiency of operation, the contrary may reduce operational efficiency, The advantage is that you do not have to install Python and the libraries that your scripts rely on on the runner's machine. Under the Linux operating system, it mainly uses the binutil inside of the toolkit ldd and objdump commands.

Pyinstaller Enter the script you specify, first analyze the other scripts that the script depends on, and then go to find, copy, and collect all the relevant scripts, including the Python parser, and then put the files in a directory, or package them in an executable file.

You can publish directly the files in the entire folder of the output, or the resulting executable file. You just have to tell the user that your app is self-contained, that you don't need to install another package, or a version of Python, and you can run it directly.

It is important to note that Pyinstaller packaged execution files can only be used in the same environment as the packaging machine system. That is, it is not portable and must be packaged for the platform if it needs to be run on a different system.

Pyinstaller a Python script into an executable program that runs on a machine without a python environment

Can run under WINDOWS,MAC and Linux operating systems.
But it is not cross-compiled, that is, under Windows with Pyinstaller generated EXE can only run under Windows, Linux under the build can only run under Linux.

Two. Pyinstaller installation under Windows

Use the command pip install Pyinstaller to
Under Windows, Pyinstaller needs PYWIN32 support. When you install Pyinstaller with PIP, PyWin32 is not found and is automatically installed Pypiwin32

If not installed automatically, download the installation yourself:

https://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/

Appear successfully installed Pyinstaller ... Indicates a successful installation!

Three. Packaging

The packaged app does not contain any source code, but the script's. pyc file is packaged.

Basic syntax:
Pyinstaller Options myscript.py
The following optional parameters are commonly used:
-f,--onefile package The results into an executable file
-d,--onedir package all results into a folder that includes an executable file and the dependent files required to execute the executable file (default)
-P dir,--paths=dir Setting the import path
--distpath=dir set the path to place the packaged results file
--specpath=dir setting the path to place the spec file
-w,--windowed is executed using Windows subsystem and does not open the command line (only valid for Windows)
-c,--nowindowed using the console subsystem (default) (only valid for Windows)
-i,--icon=<file. ico> add File.ico as an executable resource (only valid for Windows)

such as: Pyinstaller-f myfile.py

Export Python3 as EXE program

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.