In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the packaging command and exception parsing of pyinstaller components in python? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Project scenario:
Python version: 3.8
Due to the business needs of the company, it is necessary to develop a set of video conference software in the local area network, this time using Python to achieve this function.
After the program is written and the compiler implements this function, it is packaged into an application program using pyinstaller components.
Problem description:
In the process of packaging with pyinstaller components, we really encountered some problems. The main problems encountered this time are listed below:
1. How do I package multiple files?
two。 After packaging and running, the console displays "the specified module cannot be found. Mkl_intel_thread.l.dll", as shown below:
3. How can packaging eliminate unnecessary components to reduce the size of the package?
4. ✌ to be added (≧◠◡◠≦)
Cause analysis:
The packaged components are all installed by conda install, there is no problem for opencv to reference the module to run the project in the compiler, but the package will be reported to Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.l.dll, the lack of MKL files, confused for some time. (@ _;)
Solution:
First of all, of course, it is to find the Baidu god to solve the problem, ✧, searching, but to no avail, but at least let me understand a little bit of the packaging process and points for attention, combined with past code experience, this time the Anaconda opencv, numpy and mkl modules are uninstalled, the code is as follows:
Conda uninstall opencvconda uninstall numpyconda uninstall mkl
Then change it to the following:
Pip install mklpip install numpypip install opencv
It is best to install the above in order. The three components are interdependent. After installation and deployment, no error will be reported.
During the installation process, it is also found that the components installed by the two installation methods are actually different. From the size of the package, the package installed by pip install should be relatively complete, so pyinstaller packaging will not cause file loss.
Here, problem 2 is solved (the most difficult one is solved first.) (▽ ^)
Next, let's explain how to package multiple files.
First of all, you need to package multiple files, sir, into a spec file, with the following code:
Pyi-makespec app.py
This line of code generates an app.spec file in the current directory.
The generated app.spec is as follows:
#-*-mode: python Coding: utf-8-*-block_cipher = None# if you want to add a package file, add a = Analysis (['app.py'], # example: [' app.py','app1.py','app2.py'] pathex= ['C:\\ yourAppDir'], # packaging path, generally default to the current folder path binaries= [], # package static resources Here is the meta-ancestor type datas= [], # examples: [('C\ yourAppDir\\ images','images'), ('C\\ yourAppDir\\ videos','videos')] hiddenimports= [], hookspath= [], runtime_hooks= [], excludes= [], win_no_prefer_redirects=False, win_private_assemblies=False Cipher=block_cipher, noarchive=False) pyz = PYZ (a.pure, a.zipped_data, cipher=block_cipher) exe = EXE (pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], # generated execution file name name='MyAwesomeApp', # generate MyAwesomeApp.exe debug=False Bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude= [], runtime_tmpdir=None, # whether the console is displayed at runtime Note that the initials of both True and False should be capitalized console=True)
The following are common packaging commands:
Commonly used:-I add icons to applications-F specifies that only one exe file is generated after packaging-D-onedir creates a directory containing exe files, but relies on many files (default option)-c-console,-nowindowed uses console, no interface (default)-w-windowed,-noconsole uses window, no console-p adds search path
What I use here is:
Pyinstaller-F app.spec
After a while, three folders are generated in the current directory after the packaging is completed, as shown in the following figure:
The _ pycache_ folder caches your packaged files. (if the component is reinstalled, it is recommended to delete it before packaging)
The bulid folder holds some information about the packaged file.
The dist file saves the .exe file that is packaged.
Above, question 1 is over, and then the last question 3 ~ ("▽") ~ ■ Cheers □ ~ ("▽")
I remember when I packed it for the first time, I wondered why it would take more than 100 MB to write a little code and package it. (▔, ▔)
First of all, still Baidu, you will … Still don't know ("▽") to cut ~ ~
Or on their own, and finally open the compiler to take a look at the environment, suddenly found that the environment has a lot of unneeded components.
If you are afraid of bothering a conda uninstall, it is recommended to create a clean python3 environment, and then install the components you need.
(in the current Python environment, it is recommended to create a new one under the current project directory for the current project dedicated environment, initializing only two basic components, and then installing the components in the requirement.txt file)
When you pack it this way, you will find that the bag is much smaller.
I finally finished writing o (* ≧▽≦) ┏━┓.
The sad Zither Why should the sad zither have fifty strings? Each string, each strain evokes but vanished springs;
This is the answer to the question about the packaging command and exception resolution of pyinstaller components in python. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.