python - Pyinstaller,如何在尝试将 py 文件转换为 .exe 时解决“ModuleNotFoundError: No module named 'cogs'”错误?
问题描述
我一直在尝试将我的main.py文件转换为 .exe,这样用户就不必安装 python
pyinstaller --onefile -w main.py
.创建.exe文件后,我尝试运行exe并收到上述错误。我一直在使用cogs对我的命令进行分类。在下面的照片中,这些模块必须在 .exe 版本中使用。我该怎么做?有人可以帮我吗?
完整的错误信息:
Traceback (most recent call last):
File "main.py", line 212, in <module>
client.load_extension(f"cogs.{filename[:-3]}")
File "discord\ext\commands\bot.py", line 674, in load_extension
File "importlib\util.py", line 94, in find_spec
ModuleNotFoundError: No module named 'cogs'
main.py等文件的照片: main.py等文件
解决方案
#Convert .py to .exe don't use python ver 3.9 will not work, recommend 3.8:
pip install pyinstaller
#to convert to a simple exe file the exe file will be in your dist folder
pyinstaller 'fileName.py'
#to convert to a onefile exe file the exe file will be in your dist folder
pyinstaller --onefile 'fileName.py'
#to convert to a onefile exe file and the python window will not appear
pyinstaller -w --onefile 'fileName.py'
推荐阅读
- c++ - 检查字符串中的字符长度是否相同
- babeljs - Babel (@babel/types) JSDoc ast,打字在哪里?
- excel - 在 Excel VBA 中引用新工作簿
- python - 余额计算熊猫
- javascript - Gmail API 方法 users.history.list 发送不完整的消息对象作为响应
- python - 如何在 rstudio 中的 r 对象上应用 python 函数 .style.background_gradient()?
- javascript - 来自 JavaScript 文件的工作 HTML 标记(JSON jQuery?)
- javascript - JS 仅适用于第一个元素
- react-native - 应用程序被杀死时如何处理推送通知
- namespaces - Laravel Livewire 依赖门面不起作用