gpt4 book ai didi

python-3.x - 为什么不能在 cx_Freeze 中创建线程池?

转载 作者:行者123 更新时间:2023-12-04 17:35:28 25 4
gpt4 key购买 nike

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-Design/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' 添加到setup.py 脚本中build_exe_optionspackages 列表:

build_exe_options = {"packages": ['multiprocessing']}

# ...

setup( name = ..., # complete!
...
options = {"build_exe": build_exe_options},
executables = [Executable(...)])

参见 cx_Freeze documentation了解更多详情。

另请注意,您必须为卡住的脚本调用 multiprocessing.freeze_support() 才能继续使用多处理。根据documentation :

Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable. (Has been tested with py2exe, PyInstaller and cx_Freeze.)

One needs to call this function straight after the if __name__ == '__main__' line of the main module. For example:

from multiprocessing import Process, freeze_support

def f():
print('hello world!')

if __name__ == '__main__':
freeze_support()
Process(target=f).start()

If the freeze_support() line is omitted then trying to run the frozen executable will raise RuntimeError.

Calling freeze_support() has no effect when invoked on any operating system other than Windows. In addition, if the module is being run normally by the Python interpreter on Windows (the program has not been frozen), then freeze_support() has no effect.

关于python-3.x - 为什么不能在 cx_Freeze 中创建线程池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56816643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com