Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to package Python programs with PyInstaller

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to use PyInstaller to package Python programs, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Use PyInstaller to package Python programs

PyInstaller introduction:

PyInstaller is a program that converts Python programs into a single executable file. The operating system supports Windows, Linux, Mac OS X, Solaris and AIX. And many packages are available out of the box, independent of the environment.

The environment is windows7 operating system, python2.7.8 virtual environment

Official website: https://github.com/pyinstaller/pyinstaller

Detailed steps:

1Jing Win7 first install this dependency: pywin32, download it, switch to venv2.7, and then install it using easy_install xxx.exe

2Die pip installs PyInstaller:

Pip install pyinstaller

3. There may be problems that cannot be found by msvcp90.dll during the packaging process. Go to http://cn.dll-files.com/msvcp90.dll.html to download the third zip file, decompress it and put it in C:\ Windows\ System32. If it is 64-bit, put it in the C:\ Windows\ SysWOW64 directory.

4. Run the report again that MSVCR90.dll cannot be found. Similarly, go to http://cn.dll-files.com/MSVCR90.dll.html to download MSVCR90.dll and put it in C:\ Windows\ System32 and C:\ Windows\ SysWOW64.

5. Copy your entire program to a temporary folder, such as D:\ tmp\ core-wxpython, where a main.py is the execution entry.

6. Execute the build command and add the necessary search path, plus the icon of the execution file:

Cd D:\ tmp\ core-wxpythonpyinstaller-F-w-I d:\ tmp\ main.ico main.py

If you also want to add a custom dependency library, add the-p parameter:

Pyinstaller-F-w-p D:\ tmp\ core-python\ libs-I d:\ tmp\ main.ico main.py

Parameter description:

-F means to generate a single executable file

-w means to remove the console window, which is very useful in the GUI interface. However, if it is a command line program, then delete this option!

-p means that you customize the classpath that needs to be loaded, which is not needed in general.

-I represents the icon of the executable file

It is important to note that:

1)。 Check to see if the necessary modules are missing from the generated\ XXX\ build\ pyi.win32\ XXX\ warnXXX.txt (XXX is your project name). If anything is missing, add the necessary search paths as mentioned above, so that pyinstaller can find the corresponding module and integrate it at run time.

2)。 I don't have UPX here, so I'm not messing around for the time being. It is estimated that it is compressed with UPX, and the size of the exe file generated after compression will be much smaller.

The above is how to use PyInstaller to package Python programs. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report