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 solve the problem that the pyinstaller pathex parameter throws a packaged no module name exception

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to solve packaging no module name exceptions caused by pyinstaller pathex parameters". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to solve packaging no module name exceptions caused by pyinstaller pathex parameters" can help you solve your doubts.

Phenomenon:

Recently, after upgrading pyinsatller to the latest version of Version: 5.0.1 (the same method has not been encountered with version 3.5 before, there is a problem with packaging after updating to the latest version. Specifically, it is not clear which version begins to change, and we will not investigate it. Any problems encountered in the new version will be solved in the new version. The detailed phenomena and solutions are as follows:

one. First post the official introduction of pyinstaller: click Jump

two. After packaging with pyinstaller, click the prompt "no module found" when running the .exe program under the dist directory. All externally loaded modules cannot be recognized, and then put the corresponding package under the dist directory and then run, the problem disappears, indicating that the module that the corresponding directory depends on is not loaded normally when packaging.

three. Let's take a look at the packaging command first. I use batch processing, which is in the same directory as the .py main file (that is, the main window file can be run).

Echo offecho Current Dish:%~d0echo Current Dish and Path:%~dp0echo Current CMD default Dir: "% cd%" set "current_dir=%~dp0" echo% current_dir%set "output_dir=%current_dir%" cd% output_dir%;echo "% cd%" pyinstaller.exe-D-w% current_dir%\ SmartTools.py-I% current_dir%\ icon\ Tool.icopause

four. When pyinstaller is packaged, a spec file will be generated first. We can modify this file manually and specify this file to be used in the next package. Its advantage is that it can write more complex options or reuse it. I used this method in the pyinstaller 3.5 version, but in the pyinstaller5.0.1 version, the spec file I modified will be overwritten every time, resulting in the pathex being empty every time, so the files referenced in the py file will not be loaded for editing and packaging. The explanation of the pathex parameter can be found in the official section of the first step. I'll take a screenshot below to show you (tell us clearly that this parameter is mainly about the path required by the imports guide module in the file).

five. Then we already know what the problem is, but what can we do to bring the current address to the pathex in the spec file? the clear answer given above is to put the-paths parameter after the pyinstaller. Now modify and edit the package file as follows (red font is added):

Echo offecho Current Dish:%~d0echo Current Dish and Path:%~dp0echo Current CMD default Dir: "% cd%" set "current_dir=%~dp0" echo% current_dir%set "output_dir=%current_dir%" cd% output_dir%;echo "% cd%" pyinstaller.exe-- paths% current_dir%-D-w% current_dir%\ SmartTools.py-I% current_dir%\ icon\ Tool.icopause

six. After rerunning the batch, check the spec file to see if pathex has added the corresponding directory. It is confirmed that there is a value in the parameter, which is a list.

#-*-mode: python Coding: utf-8-*-block_cipher = None a = Analysis (['E:\\ SmartTools\ SmartTools.py'], pathex= ['E:\\ SmartTools\], binaries= [], datas= [], hiddenimports= [], hookspath= [], hooksconfig= {}, runtime_hooks= [], excludes= [], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False,)

seven. Go back to the dist directory to execute the .exe program, start normally without reporting any errors, and the problem is solved successfully.

After reading this, the article "how to solve packaging no module name exceptions caused by pyinstaller pathex parameters" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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