Home  >  Article  >  Backend Development  >  Can python generate exe programs?

Can python generate exe programs?

anonymity
anonymityOriginal
2019-06-14 11:48:125783browse

Python is a scripting language that is interpreted and executed by the interpreter. It has 3 publishing methods.

Can python generate exe programs?

.py file: For open source projects or if the source code is not that important, the source code is provided directly, and the user needs to install Python by themselves and install all the dependencies. seed bank. (This is what Python official installation packages do)

.pyc file: Some companies or individuals do not want the source code to be seen by the operator due to confidentiality or various reasons. You can Publish using pyc files. The pyc file is a binary code that can be recognized by the Python interpreter, so it is cross-platform after publishing. Users need to install the corresponding version of Python and dependent libraries.

Executable file: For non-coders or novice users, it would be a disaster if you ask them to install Python while also tossing a bunch of dependent libraries. For such users, the easiest way is to provide an executable file and just tell them how to use it. What is more troublesome is that different executable files need to be packaged for different platforms (Windows, Linux, Mac,...).

This article mainly introduces the last method. Both .py and .pyc are relatively simple, and Python itself can handle it. There are many ways to package Python scripts into executable files. This article focuses on PyInstaller.

Introduction to PyInstaller

PyInstaller actually combines the python parser with you Packaging your own script into an executable file is completely different from compiling it into real machine code, so don't expect that packaging it into an executable file will improve the running efficiency. On the contrary, it may reduce the running efficiency. The advantage is that it is running There is no need to install python and the libraries your script depends on on your machine. Under the Linux operating system, it mainly uses the ldd and objdump commands in the binutil tool package.

PyInstaller enters the script you specified, first analyzes other scripts that the script depends on, then searches, copies, collects all related scripts, including the Python parser, and then puts these files in a directory Download it, or package it into an executable file.

You can directly publish the files in the entire output folder, or the generated executable file. You only need to tell users that your application is self-contained and does not require the installation of other packages or a certain version of Python before it can be run directly.

It should be noted that the executable files packaged by PyInstaller can only be used in the same environment as the packaging machine system. In other words, it is not portable and must be packaged for that platform if it needs to run on a different system.

pyinstaller packages Python scripts into executable programs so that they can be run on machines without a Python environment

The latest version is pyinstaller 3.1.1 . Supports python2.7 and python3.3.

Can run under Windows, Mac and Linux operating systems.

But it is not cross-compiled, which means that the exe generated by PyInstaller under Windows can only run under Windows, and the exe generated under Linux can only run under Linux.

The above is the detailed content of Can python generate exe programs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Can shell execute python?Next article:Can shell execute python?