ImportError: cannot import name '_ni_support' -- 使用 cx-freeze 和 scipy

Posted

技术标签:

【中文标题】ImportError: cannot import name \'_ni_support\' -- 使用 cx-freeze 和 scipy【英文标题】:ImportError: cannot import name '_ni_support' -- Using cx-freeze with scipyImportError: cannot import name '_ni_support' -- 使用 cx-freeze 和 scipy 【发布时间】:2018-06-11 22:43:05 【问题描述】:

我使用cx-freeze 从我的 python 3 脚本中创建了一个可执行文件。问题是显然cx-freeze 很难导入scipy 脚本。我以前必须解决其他问题,例如手动添加tcl 库文件。无论如何,我的设置文件如下:

from cx_Freeze import setup, Executable
import os 

os.environ['TCL_LIBRARY'] = "C:\\Users\\Gobryas\\AppData\\Local\\Continuum\\anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Gobryas\\AppData\\Local\\Continuum\\anaconda3\\tcl\\tk8.6"

additional_mods = ['numpy.core._methods', 'numpy.lib.format']

setup(name = "Curve Characterization" ,
  options = 'build_exe': 'includes': additional_mods,
  version = "0.1" ,
  description = "" ,
  executables = [Executable("curvCharLite.py")])

这是我得到的错误:

ImportError: 无法导入名称“_ni_support”

详细信息

Traceback (most recent call last):
 File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
 File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
 File "curvCharLite.py", line 21, in <module>
 File "c:\users\Gobryas\documents\mo\project 1\ruptures\ruptures\__init__.py", line 8, in <module>
from .detection import (Binseg, BottomUp, Dynp, Omp, OmpK, Pelt, Window,
 File "c:\users\Gobryas\documents\mo\project 1\ruptures\ruptures\detection\__init__.py", line 51, in <module>
from .window import Window
 File "c:\users\Gobryas\documents\mo\project 1\ruptures\ruptures\detection\window.py", line 112, in <module>
from scipy.signal import argrelmax
 File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\__init__.py", line 311, in <module>
from ._savitzky_golay import savgol_coeffs, savgol_filter
 File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\signal\_savitzky_golay.py", line 6, in <module>
from scipy.ndimage import convolve1d
 File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\ndimage\__init__.py", line 161, in <module>
from .filters import *
 File "C:\Users\Gobryas\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\ndimage\filters.py", line 35, in <module>
from . import _ni_support
ImportError: cannot import name '_ni_support'

PS 1:有一个类似的问题问here,但没有真正有用的答案。

PS 2:我正在使用scipy 1.1.0、cx-freeze 5.1.1 和python 3.6.5

【问题讨论】:

【参考方案1】:

所以,我想我在@fepzzz 的the post 的启发下找到了解决这个问题的方法。 cx-freezescipy 之间似乎存在严重冲突,可以通过以下方式避免。我需要修改include_files 构建选项如下:

import os
import scipy

includefiles_list=[]
scipy_path = os.path.dirname(scipy.__file__)
includefiles_list.append(scipy_path)

build_options = dict(packages=['matplotlib'], #this line solves an issue w/ matplotlib
                 include_files=includefiles_list, #this line is for scipy issue
                 includes=['matplotlib.backends.backend_qt5agg']) #this line solves another issue w/ matplotlib

希望这对其他人有所帮助。

【讨论】:

以上是关于ImportError: cannot import name '_ni_support' -- 使用 cx-freeze 和 scipy的主要内容,如果未能解决你的问题,请参考以下文章

解决 ImportError: cannot import name pywrap_tensorflow

ImportError: cannot import name webdriver

ImportError: cannot import name patterns

window环境下ImportError: cannot import name 'Bar' from 'pyecharts'

ImportError: cannot import name 'DjangoSuitConfig'

ImportError: cannot import name ‘DtypeArg‘ from ‘pandas