Cx_freeze ImportError no module named scipy

后端 未结 3 1671
误落风尘
误落风尘 2020-12-09 13:06

Good day all,

I am having trouble using cx_Freeze on a code I am working on converting to a .exe.

When I run cx_Freeze I get the following ImportError that t

相关标签:
3条回答
  • 2020-12-09 13:41

    For all the Scipy related issues gets resolved if you include them in the script. It worked for me. Please refer my working script (Note: this script doesnot have any UI library like tkinter)

    This scripts fetches the data from config file and returns the addition two number which is get written in the file in the working directory.

    FolderStructure

    setup.py

    import sys
    import cx_Freeze
    from cx_Freeze import setup, Executable
    from scipy.sparse.csgraph import _validation
    import scipy
    import matplotlib
    
    '''Include the package for which you are getting error'''
    packages = ['matplotlib','scipy']
    executables = [cx_Freeze.Executable('main.py', base='Win32GUI')]
    
    '''include the file of the package from python/anaconda installation '''
    include_files = ['C:\\ProgramData\\Continuum\\Anaconda\\Lib\\site-packages\\scipy']
    
    cx_Freeze.setup(
        name = 'Test1',
        options = {'build_exe': {'packages':packages,
            'include_files':include_files}},
        version = '0.1',
        description = 'Extraction of data',
        executables = executables
        )
    

    main.py

    import os, numpy as np
    import configparser
    from helper_scripts.help1 import Class_A
    
    path = os.path.dirname(os.path.abspath('__file__')) + '\\'
    conf = configparser.ConfigParser()
    conf.read(path + 'config.ini')
    
    a = eval(conf.get('inputs','input_1'))
    b = eval(conf.get('inputs','input_2'))
    
    obj = Class_A()
    
    res = obj.getData(a,b)
    
    if not os.path.exists(path + 'Result.txt'):
        with open(path + 'Result.txt', 'w', encoding ='utf-8') as f:
            f.write(f'result is : {str(res)}\n')
    
    else:
        with open(path + 'Result.txt', 'a', encoding ='utf-8') as f:
            f.write(f'result is : {str(res)}\n')
    

    Command to generate the exe file

    ''' make sure  to run the below command from working directory where the setup.py file is present.'''
    
    python setup.py build
    

    The build folder gets created with main.exe file all the required binaries files.

    Note: Place the config.ini file in the exe folder so that exe can access the config file and produce the output.

    0 讨论(0)
  • 2020-12-09 13:57

    I had exactly the same issue. Found the solution here: https://bitbucket.org/anthony_tuininga/cx_freeze/issues/43/import-errors-when-using-cx_freeze-with

    Find the hooks.py file in cx_freeze folder. Change line 548 from finder.IncludePackage("scipy.lib") to finder.IncludePackage("scipy._lib").

    Leave the "scipy" entry in packages and delete 'C:\Python34\Lib\site-packages\scipy' in include_files.

    0 讨论(0)
  • 2020-12-09 14:02

    Unfortunately I still don't have rep to comment, but for the op having issues with the "No module named scipy.spatial.ckdtree" error, I solved it by simply renaming "cKDTree.cp37-win_amd64" to "ckdtree.cp37-win_amd64" under scipy\spatial folder. I had similar issues with libraries being imported with capital letters here and there.

    0 讨论(0)
提交回复
热议问题