ImportError: cannot import name 'LinearNDInterpolator'
ImportError: cannot import name 'LinearNDInterpolator'
我在 Python 3.6.2 中编写了一个程序,我试图使用 cx_Freeze 冻结分发。但是我在尝试 运行 生成的可执行文件时遇到了一个奇怪的错误(我的基本程序使用 pyLDAvis.sklearn)。错误重现如下:
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "MYPROGRAM.py", line 1474, in <module>
import pyLDAvis.sklearn
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\pyLDAvis\__init__.py", line 44, in <module>
from ._display import *
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\pyLDAvis\_display.py", line 13, in <module>
from ._prepare import PreparedData
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\pyLDAvis\_prepare.py", line 15, in <module>
from scipy.stats import entropy
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\__init__.py", line 345, in <module>
from .stats import *
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\stats.py", line 171, in <module>
from . import distributions
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 16, in <module>
from scipy.misc import doccer
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\misc\__init__.py", line 68, in <module>
from scipy.interpolate._pade import pade as _pade
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\interpolate\__init__.py", line 187, in <module>
from .ndgriddata import *
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\interpolate\ndgriddata.py", line 11, in <module>
from .interpnd import LinearNDInterpolator, NDInterpolatorBase, \
ImportError: cannot import name 'LinearNDInterpolator'
我的 cx_freeze 脚本的可执行选项如下:
build_exe_options = {
"packages": ["os","textwrap","msvcrt","warnings","time","datetime","platform","sklearn","operator","nltk.tokenize","stop_words","pandas","nltk.stem.porter","sklearn.feature_extraction.text","sklearn.decomposition","progressbar","numpy","packaging","asyncio",
],
"includes": ["appdirs","packaging.version","packaging.specifiers","packaging.requirements","pyLDAvis.sklearn","pyLDAvis.urls","scipy.sparse.csgraph._validation"],
"excludes" : ["tkinter","sqlite3"],
"include_msvcr" : True
}
我似乎无法找到 scipy.interpolate 或 scipy.interpolate.interpnd 的任何组合来放入构建选项以使其工作 - 我一直收到 "can't import name 'LinearNDInterpolator'" 错误.重新安装 scipy 没有帮助。
有人可以指教吗?我只是注定无法冻结我的代码吗?
你试过添加
import scipy.interpolate.interpnd
在你的基础程序中(不在安装脚本中)?那会发生什么?
根据我目前的经验,需要将scipy
添加到packages
列表中才能使其被[=14=正确包含].但是由于 this issue,还需要将 scipy.spatial.cKDTree
添加到 excludes
列表中。因此,请尝试在安装脚本中使用以下选项:
build_exe_options = {
"packages": ["os","textwrap","msvcrt","warnings","time","datetime","platform","sklearn","operator","nltk.tokenize","stop_words","pandas","nltk.stem.porter","sklearn.feature_extraction.text","sklearn.decomposition","progressbar","numpy","packaging","asyncio","scipy"
],
"includes": ["appdirs","packaging.version","packaging.specifiers","packaging.requirements","pyLDAvis.sklearn","pyLDAvis.urls","scipy.sparse.csgraph._validation"],
"excludes" : ["tkinter","sqlite3","scipy.spatial.cKDTree"],
"include_msvcr" : True
}
补充说明:build_exe
选项 "include_msvcr": True
似乎对 cx_Freeze
版本 5.0.2、5.1.1 和 6.0b1 没有影响。请参阅 this issue,我的 post 那里 (jpeg13) 包含更多详细信息。您可能需要使用 build_exe
选项 include_files
.
手动添加 MSVCR DLL
我在 Python 3.6.2 中编写了一个程序,我试图使用 cx_Freeze 冻结分发。但是我在尝试 运行 生成的可执行文件时遇到了一个奇怪的错误(我的基本程序使用 pyLDAvis.sklearn)。错误重现如下:
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "MYPROGRAM.py", line 1474, in <module>
import pyLDAvis.sklearn
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\pyLDAvis\__init__.py", line 44, in <module>
from ._display import *
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\pyLDAvis\_display.py", line 13, in <module>
from ._prepare import PreparedData
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\pyLDAvis\_prepare.py", line 15, in <module>
from scipy.stats import entropy
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\__init__.py", line 345, in <module>
from .stats import *
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\stats.py", line 171, in <module>
from . import distributions
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 16, in <module>
from scipy.misc import doccer
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\misc\__init__.py", line 68, in <module>
from scipy.interpolate._pade import pade as _pade
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\interpolate\__init__.py", line 187, in <module>
from .ndgriddata import *
File "C:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\interpolate\ndgriddata.py", line 11, in <module>
from .interpnd import LinearNDInterpolator, NDInterpolatorBase, \
ImportError: cannot import name 'LinearNDInterpolator'
我的 cx_freeze 脚本的可执行选项如下:
build_exe_options = {
"packages": ["os","textwrap","msvcrt","warnings","time","datetime","platform","sklearn","operator","nltk.tokenize","stop_words","pandas","nltk.stem.porter","sklearn.feature_extraction.text","sklearn.decomposition","progressbar","numpy","packaging","asyncio",
],
"includes": ["appdirs","packaging.version","packaging.specifiers","packaging.requirements","pyLDAvis.sklearn","pyLDAvis.urls","scipy.sparse.csgraph._validation"],
"excludes" : ["tkinter","sqlite3"],
"include_msvcr" : True
}
我似乎无法找到 scipy.interpolate 或 scipy.interpolate.interpnd 的任何组合来放入构建选项以使其工作 - 我一直收到 "can't import name 'LinearNDInterpolator'" 错误.重新安装 scipy 没有帮助。
有人可以指教吗?我只是注定无法冻结我的代码吗?
你试过添加
import scipy.interpolate.interpnd
在你的基础程序中(不在安装脚本中)?那会发生什么?
根据我目前的经验,需要将
scipy
添加到packages
列表中才能使其被[=14=正确包含].但是由于 this issue,还需要将scipy.spatial.cKDTree
添加到excludes
列表中。因此,请尝试在安装脚本中使用以下选项:build_exe_options = { "packages": ["os","textwrap","msvcrt","warnings","time","datetime","platform","sklearn","operator","nltk.tokenize","stop_words","pandas","nltk.stem.porter","sklearn.feature_extraction.text","sklearn.decomposition","progressbar","numpy","packaging","asyncio","scipy" ], "includes": ["appdirs","packaging.version","packaging.specifiers","packaging.requirements","pyLDAvis.sklearn","pyLDAvis.urls","scipy.sparse.csgraph._validation"], "excludes" : ["tkinter","sqlite3","scipy.spatial.cKDTree"], "include_msvcr" : True }
补充说明:
build_exe
选项"include_msvcr": True
似乎对cx_Freeze
版本 5.0.2、5.1.1 和 6.0b1 没有影响。请参阅 this issue,我的 post 那里 (jpeg13) 包含更多详细信息。您可能需要使用build_exe
选项include_files
. 手动添加 MSVCR DLL