7

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:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "gis_helper.py", line 13, in <module>
  File "C:\Python27\lib\site-packages\scipy\__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.\n')
    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.

Praxis
  • 934
  • 2
  • 17
  • 31

2 Answers2

13

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))
fepzzz
  • 146
  • 1
  • 4
  • Thanks that did work, unfortunately it's now moved onto other errors. Focussing on pyinstaller for the time being, but thanks for your help. – Praxis Sep 30 '15 at 12:37
  • I have the same issue. All tough when i test your code i get the following message `ImportError: No module named 'C:\\***\\***\\Python27\\lib\\site-packages\\scipy` – Bridgekeeper Apr 12 '16 at 09:00
  • The dirname() refers to os.path.dirname(), I suppose. How did you "add the includefiles to the buildExe parameter list"? – Niko Föhr Dec 05 '16 at 11:41
  • @np8, yes, dirname() refers to os.path.dirname(). I have updated my answer. Also check http://cx-freeze.readthedocs.io/en/latest/distutils.html – fepzzz Dec 08 '16 at 15:31
1

I add the same problem and solved it using fepzzz method and including some missing packages:

additional_mods = ['numpy.matlib', 'multiprocessing.process']
includefiles = [(r'C:\Anaconda3\Lib\site-packages\scipy')]

setup(xxx, options={'build_exe': {'includes': additional_mods, 'include_files': includefiles}})

And using version 5.0.2 of cx-Freeze package, which solved an error when importing multiprocessing.process

Ad_bzh
  • 11
  • 1