python-3.x - 为什么我不能在 cx_Freeze 中创建线程池?
问题描述
Traceback (most recent call last):
File "C:\Users\Jun\AppData\Local\Programs\Python\Python35\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Users\Jun\AppData\Local\Programs\Python\Python35\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "D:/ruanjian/new/Ui-Disign/hand_up_625.py", line 25, in <module>
from keras.models import load_model
File "C:\Users\Jun\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Users\Jun\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\__init__.py", line 4, in <module>
from . import data_utils
File "C:\Users\Jun\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\data_utils.py", line 19, in <module>
from multiprocessing.pool import ThreadPool
ImportError: No module named 'multiprocessing.pool'
解决方案
尝试添加'multiprocessing'
到脚本中的packages
列表:build_exe_options
setup.py
build_exe_options = {"packages": ['multiprocessing']}
# ...
setup( name = ..., # complete!
...
options = {"build_exe": build_exe_options},
executables = [Executable(...)])
有关详细信息,请参阅 cx_Freeze文档。
另请注意,您必须调用multiprocessing.freeze_support()
冻结脚本才能继续使用多处理。根据文档:
添加对使用多处理的程序被冻结以生成 Windows 可执行文件时的支持。(已使用py2exe、PyInstaller和cx_Freeze进行测试。)
需要
if __name__ == '__main__'
在主模块的行之后直接调用此函数。例如:from multiprocessing import Process, freeze_support def f(): print('hello world!') if __name__ == '__main__': freeze_support() Process(target=f).start()
如果
freeze_support()
省略该行,则尝试运行冻结的可执行文件将引发 RuntimeError。
freeze_support()
在 Windows 以外的任何操作系统上调用时调用无效。另外,如果模块在 Windows 上被 Python 解释器正常运行(程序没有被冻结),则freeze_support()
没有效果。
推荐阅读
- python - 如果元素不是无,则在列表中添加元素的优雅方式
- python - Python 在 true 时将值增加 100
- python - 从 Python sys.exit 字符串在 gnu make 中分配变量
- python-3.x - 图表上的简单椭圆(pyplot、k-means Coursera 课程)
- javascript - 每十分钟重新加载 html 页面
- c++ - 在 C++ 中,指针类型数组的元素是否默认保证初始化为 nullptr?
- python - 如何删除重复的数组元素并在python中保持第一次出现?
- docker - 有没有办法将 Dockerfile 转换为 EC2 实例(例如)?
- rust - impl TryFrom 的优缺点是什么
对于 Foo vs impl From 结果 对于错误的转换? - swift - 表格视图未获取核心数据日期