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
413 views
in Technique[技术] by (71.8m points)

python - Cx_freeze ImportError no module named scipy

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 there no no module named scipy

running install
running build
running build_exe
Traceback (most recent call last):
  File "setup.py", line 25, in <module>
    executables = executables
  File "C:Python34libsite-packagescx_Freezedist.py", line 362, in setup
    distutils.core.setup(**attrs)
  File "C:Python34libdistutilscore.py", line 148, in setup
    dist.run_commands()
  File "C:Python34libdistutilsdist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:Python34libdistutilsdist.py", line 974, in run_command
    cmd_obj.run()
  File "C:Python34libdistutilscommandinstall.py", line 539, in run
    self.run_command('build')
  File "C:Python34libdistutilscmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:Python34libdistutilsdist.py", line 974, in run_command
    cmd_obj.run()
  File "C:Python34libdistutilscommanduild.py", line 126, in run
    self.run_command(cmd_name)
  File "C:Python34libdistutilscmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:Python34libdistutilsdist.py", line 974, in run_command
    cmd_obj.run()
  File "C:Python34libsite-packagescx_Freezedist.py", line 232, in run
    freezer.Freeze()
  File "C:Python34libsite-packagescx_Freezefreezer.py", line 619, in Freeze
    self.finder = self._GetModuleFinder()
  File "C:Python34libsite-packagescx_Freezefreezer.py", line 378, in _GetModuleFinder
    finder.IncludePackage(name)
  File "C:Python34libsite-packagescx_Freezefinder.py", line 686, in IncludePackage
    module = self._ImportModule(name, deferredImports)
  File "C:Python34libsite-packagescx_Freezefinder.py", line 386, in _ImportModule
    raise ImportError("No module named %r" % name)
ImportError: No module named 'scipy'

I can confirm that I have Scipy 0.16 installed on my system which works when I import it into other python code. I am currently running python 3.4 on Windows. The following is my setup.py file for cx_Freeze.

import cx_Freeze
import sys
import matplotlib

base = None

if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [cx_Freeze.Executable('fractureGUI.py', base=base, icon='star_square.ico')]

packages = ['tkinter','matplotlib','scipy']

include_files = ['star_square.ico', 'C:\Python34\Lib\site-packages\scipy']

cx_Freeze.setup(
    name = 'FracturePositionMonteCarlo',
    options = {'build_exe': {'packages':packages,
        'include_files':include_files}},
    version = '0.01',
    description = 'Fracture Depth Monte Carlo',
    executables = executables
    )

The following is the import section of my main script, fractureGUI.py.

import scipy
from random import random

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib import style
style.use('ggplot')

import tkinter as tk
from tkinter import ttk, filedialog

import sys
import json

If anybody has any ideas why cx_Freeze is unable to find scipy please do let me know. I tried to add the filepath to scipy under include_files but it made no difference.

Kind regards,

Jonnyishman

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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:Python34Libsite-packagesscipy' in include_files.


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

...