📜  pyinstaller windows - Python (1)

📅  最后修改于: 2023-12-03 15:33:50.817000             🧑  作者: Mango

PyInstaller for Windows - Python

Introduction

As a Python developer, if you want to distribute your application to others, you need to create an executable file which can be run on other machines without any Python environment setup. PyInstaller is a Python package which is used to convert a Python program into a standalone executable file. PyInstaller supports multiple platforms and can be used to create a standalone executable file for Windows, MacOS and Linux.

Installation

To install PyInstaller, you can use the pip package manager. Open the command prompt and run the following command:

pip install pyinstaller
Usage

To create an executable file, you need to run the following command on the command prompt:

pyinstaller myscript.py

Here, myscript.py is the Python file which you want to convert into an executable file.

PyInstaller will create a folder named dist which will contain the executable file, along with any other files required to run the application. By default, PyInstaller will create a single executable file named myscript which can be run on any Windows machine without any Python environment setup.

Advanced Usage

PyInstaller provides many options to customize the generated executable file. You can specify options on the command line, or you can create a configuration file named pyinstaller.spec. For example, you can use the following command to create a single executable file named myscript.exe:

pyinstaller --onefile --name myscript myscript.py

Here, the option --onefile creates a single executable file instead of a folder, and --name myscript specifies the name of the executable file.

You can also specify the icon file for the executable file:

pyinstaller --onefile --name myscript --icon=myicon.ico myscript.py

This command will create a single executable file named myscript.exe with the icon file myicon.ico.

Conclusion

PyInstaller is a great tool for Python developers who want to distribute their applications as executable files. It is easy to use and provides many options to customize the generated executable file. With PyInstaller, you can create a standalone executable file for Windows with just a few commands.