简体   繁体   English

pyinstaller没有名为错误的模块

[英]pyinstaller no module named error

first of all: python 2.7, pyinstaller 3.3.1 首先:python 2.7,pyinstaller 3.3.1

I am new to pyinstaller and flask, and I am trying to develop a little app for my embedded linux system. 我是pyinstaller和flask的新手,我正在尝试为嵌入式Linux系统开发一个小应用程序。

The key point is that each time I generate my app with pyinstaller, it works, but when I run it, it does not. 关键是每次使用pyinstaller生成我的应用程序时,它都可以运行,但是当我运行它时,它却无法运行。

My last error is the following: 我的最后一个错误是以下内容:

Traceback (most recent call last):
  File "hello.py", line 22, in <module>
  File "flask/app.py", line 943, in run
  File "werkzeug/serving.py", line 812, in run_simple
  File "werkzeug/_reloader.py", line 273, in run_with_reloader
  File "werkzeug/_reloader.py", line 152, in run
  File "werkzeug/_reloader.py", line 22, in _iter_module_files
  File "email/__init__.py", line 79, in __getattr__
ImportError: No module named image

As far as I am concerned, I do not need this module, but to me, the most important thing is knowing where to find those hidden dependencies. 就我而言,我不需要此模块,但是对我来说,最重要的是知道在哪里可以找到那些隐藏的依赖项。 What I really want to know is a method in order to look for those dependencies and change my script for generating my bunddle with pyinstaller. 我真正想知道的是一种寻找这些依赖关系并更改脚本以使用pyinstaller生成捆绑包的方法。 Till now, I use this line for generating my bunddle: 到现在为止,我使用以下行来生成捆绑包:

pyinstaller --noupx --hiddenimport email.mime.message --hiddenimport image hello.py pyinstaller --noupx --hiddenimport email.mime.message --hiddenimport图像hello.py

The second hidden import is wrong, but, how can I know which import is missing??? 第二个隐藏的导入是错误的,但是,我怎么知道缺少哪个导入??? Where do I have to search those modules? 我必须在哪里搜索这些模块?

My first hidden import (email.mime.message) had a similar message that just said that there was a missing import "message". 我的第一个隐藏导入(email.mime.message)也有类似的消息,只是说缺少导入“消息”。 I could read here the solution for that, but it was a matter of luck! 我可以在这里阅读解决方案,但是这很幸运!

How do I know from that message what is the necessary dependency?? 我如何从该消息中知道什么是必要的依赖关系?

Thranks a lot ! 大发脾气!

You should run this for it to work: 您应该运行它以使其工作:

pyinstaller -F -w \
--onefile \
--hidden-import='email.mime.multipart' \
--hidden-import='email.mime.message' \
--hidden-import='email.mime.text' \
--hidden-import='email.mime.image' \
--hidden-import='email.mime.audio' \
--hidden-import='sqlalchemy.sql.default_comparator' \
--hidden-import='jinja2' \
main.py

Thanks to mrf345 感谢mrf345

from PyInstaller.utils.hooks import collect_data_files, eval_statement, collect_submodules

datas = collect_submodules('email.mime')

hidden_imports = ['sqlalchemy.sql.default_comparator', 'jinja2'] + datas

add this to your .spec file generated from the pyi-makespec, More info at https://pythonhosted.org/PyInstaller/hooks.html#understanding-pyinstaller-hooks 将此添加到从pyi-makespec生成的.spec文件中,有关更多信息, 参见https://pythonhosted.org/PyInstaller/hooks.html#understanding-pyinstaller-hooks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM