如何使用包含sklearn的py2exe?

use*_*846 5 python py2exe

如果代码有import sklearn,使用后py2exe

然后运行"exe"文件,我得到了这个错误日志:

Traceback (most recent call last):
File "HelloSklearn.py", line 17, in <module>
File "sklearn\__init__.pyc", line 32, in <module>
File "sklearn\base.pyc", line 8, in <module>
File "scipy\sparse\__init__.pyc", line 191, in <module>
File "scipy\sparse\csgraph\__init__.pyc", line 146, in <module>
File "scipy\sparse\csgraph\_shortest_path.pyc", line 12, in <module>
File "scipy\sparse\csgraph\_shortest_path.pyc", line 10, in __load
File "_shortest_path.pyx", line 18, in init scipy.sparse.csgraph._shortest_path(scipy\sparse\csgraph\_shortest_path.c:14235)
ImportError: No module named _validation
Run Code Online (Sandbox Code Playgroud)

dan*_*van 4

您可以添加scipy.sparse.csgraph._validation到脚本includes中的选项setup.py

setup( 
    ...
    options = { 'includes': ['scipy.sparse.csgraph._validation'] }
)
Run Code Online (Sandbox Code Playgroud)

或者只是py2exe通过强制导入来强制发现它 - 在代码中的某处放置

import scipy.sparse.csgraph._validation
Run Code Online (Sandbox Code Playgroud)