In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
It is believed that many inexperienced people do not know what to avoid in Python packaging Exe program. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
After writing a python program, how to quickly share the code with others, especially for beginners, it is very fulfilling to be able to package your code as an exe program and transfer it to other people's computers. Fortunately, python comes with its own simple packaging program, so that many people can have the addiction of being a programmer. At present, the popular packing libraries are py2exe, pyinstaller and cx_Freeze.
However, the running environment of python is complex, and the programs written are often realized with the help of many additional functional libraries, which will cause some difficulties to simple packaging. I also feel that pyinstaller has the highest success rate after many packaging failures and successes, so it is necessary to write a pit avoidance guide for pyinstaller.
I. installation
Use the pip installation of python, in the cmd window, use pip install pyinstaller, and the installation is complete. Then configure the environment variables.
2. Use
For example, open the cmd window in the folder where the program 6.py is located. Generally enter pyintaller-F * *. Py (the exact meaning of the command character is explained below), and enter will begin to pack. If all goes well, there will be feedback on successful packaging, as shown in the following figure, which means that the file has been packaged. The packaged exe program is stored in the dist folder and can be cut out when you use it. If you are lucky or the program is relatively simple, then this exe can run on any computer.
But often not so easy, pyinstaller in the use of a lot of holes, the beginning of packaging, is also the beginning of repair.
III. Fill in the pit when you encounter it.
1. Chinese cannot appear in the file path
Otherwise, the following error will occur directly in the packaging process. At this point, just change the folder and program name to English or numbers and repackage it. You can change the name of exe back after packing.
two。 Missing import hook file
Sometimes even if the package is successful, when running exe, there will still be an error and flicker.
If the error is: FileNotFoundError: [Errno 2] No such file or directory:.
The hook file is missing. Add a custom hook to hook in the installation path of pyinstaller. The naming convention of the hook file is: hook- [library name] .py. For example, if I use the function library of stuttering participle in the packaging program as an example, I will create a hook-jieba.py and write:
From PyInstaller.utils.hooks import collect_data_files datas = collect_data_files ("jieba")
Then put it into ~\ Lib\ site-packages\ PyInstaller\ hooks, and run pyinstaller packaging again to solve the problem.
3. Missing import function library module
If the error is no moduler named "pandas._libs.skiplist", you have to manually import the library. The solution is to open the generated spec file, find hiddenimports= [], add the library to be added, change it as follows, hiddenimports= ["pandas._libs.skiplist"], then delete the exe file in dist, and repackage it with spec file, pyinstaller * * .spec. The problem can be solved.
Fancy packing
Several important parameters related to packaging are as follows.
-F, package all the content into an exe, which is easy to send. This parameter is usually used.
-c, which is the default option for windows systems. Using this parameter, the runtime will have a black window console.
-w, with this parameter, the black window console does not appear at run time.
-I use this parameter to generate the exe of the custom icon, followed by the address of the ico image. For example, pyinstaller-I D:\ icons\ demo.ico *. Py
The program will be packaged into exe to send out or for users to download, is a more traditional way of communication, and relatively cumbersome, in fact, with a simple H5 or Mini Program can achieve the same effect, more convenient for users, but also towards the direction of light application development. In addition, for professional users, it can also be spread through github and api. With the popularity of the concept of the network and the arrival of the 5G era, I believe that there is a better way to transfer the functions of the tools to the users they need more safely, quickly and privately.
After reading the above, have you mastered the ways to avoid the pitfalls that need to be avoided in Python packaging Exe programs? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.