Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 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 Reply

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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...