Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

cx freeze - Scipy and CX_freeze - Error importing scipy: you cannot import scipy while being in scipy source directory

I'm having trouble compiling an exe while using cx_freeze and scipy. In particular, my script uses

from scipy.interpolate import griddata

The build process seems to complete successfully, however when I try to run the compiled exe, I get the following message.

Traceback (most recent call last):
  File "C:Python27libsite-packagescx_FreezeinitscriptsConsole.py", line 27, in <module>
    exec(code, m.__dict__)
  File "gis_helper.py", line 13, in <module>
  File "C:Python27libsite-packagesscipy\__init__.py", line 103, 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 intepreter.

After looking at scipy _init__.py file, there is the following:

if __SCIPY_SETUP__:
    import sys as _sys
    _sys.stderr.write('Running from scipy source directory.
')
    del _sys
else:
    try:
        from scipy.__config__ import show as show_config
    except ImportError:
        msg = """Error importing scipy: you cannot import scipy while
        being in scipy source directory; please exit the scipy source
        tree first, and relaunch your python intepreter."""
        raise ImportError(msg)

I'm not entirely sure what is the problem here however although it seems that the erros is being thrown because there is a problem with the scipy config file. Possibly not being included in the build process. I'm quite a novice and hoping someone more experienced with generating build using cxfreeze can shed some light on this.

Incidentally, the scipy in use was installed from binaries here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

i have had the same issue. I added this code to the setup.py generated by cx_freeze:

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

Then, used includefiles_list as part of the build_exe parameter:

build_options = dict(packages=[], include_files=includefiles_list)

setup(name="foo", options=dict(build_exe=build_options))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...