cx_Freeze 5.0: ImportError: No module named 'scipy.__config__'

匿名 (未验证) 提交于 2019-12-03 08:28:06

问题:

Problem

I get the following error when trying to run an .exe built with cx_Freeze:

File "C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>   from scipy.__config__ import show as show_config ImportError: No module named 'scipy.__config__'  During handling of the above exception, another exception occurred: ... File "C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>    raise ImportError(msg) ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python interpreter. 

How could I troubleshoot this?

Additional Information

Setup

  • Windows 7 Enterprise 64-bit
  • WinPython-64bit-3.5.2.3Qt5 (Python 3.5.2 64-bit)
  • cx_Freeze 5.0 (*)
  • scipy 0.18.1

(*) With pythoncom fix in the hooks.py

setup.py:

import os import sys from cx_Freeze import setup, Executable  os.environ['TCL_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tcl8.6"  os.environ['TK_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tk8.6"    base = 'Console' if sys.platform == 'win32':     base = 'Win32GUI'  options = {     'build_exe': {         'excludes': ['gtk', 'PyQt4', 'Tkinter'],     } }   executables = [     Executable('GUI.py', base=base) ]   setup(name='GUI',       version='0.1',       description='GUI test',       executables=executables,       options=options       ) 

Errors during build

None.

What else have I tried?

1) Tried to add 'includes': ['scipy.__config__'] to the setup.py.

  • Result: error during build ImportError: No module named 'scipy.__config__'

2) Tried to add 'packages': ['scipy'], to the setup.py.

  • Result: error during build ImportError: No module named 'scipy'

3) Renamed the finder.IncludePackage("scipy.lib") in the cx_Freeze/hooks.py to finder.IncludePackage("scipy._lib") as instructed in the answer of the SO Question "Cx_freeze ImportError no module named scipy" + added 'packages': ['scipy'], to the setup.py.

  • Result: No build-time errors. When trying to run the .exe, it gives ImportError: No module named 'scipy.spatial.ckdtree'
  • Tried also with 'includes': ['scipy.spatial.ckdtree'] in the setup.py, but the problem persists.
  • The build output has the following lines:

    m scipy.spatial.cKDTree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\cKDTree.cp35-win_amd64.pyd m scipy.spatial.ckdtree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\ckdtree.cp35-win_amd64.pyd

回答1:

I think I have a solution (not the greatest but it works). Go to the scipy\spatial directory (within the build directory) and change the file from cKDTree.cp36-win_amd64.pyd to ckdtree.cp36-win_amd64.pyd.

NOTE: your file name might be slightly different depending which python version but the main thing is to use lowercase kdt in the file name.

The capital letters is the problem. It worked for me.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!