0

我正在尝试在使用库 assimulo(微分方程求解器)的软件上使用 py2exe 构建可执行文件。遇到的问题是在执行过程中我收到:

ImportError:没有名为代数的模块

确切的错误信息是:

Traceback (most recent call last):
  File "main.py", line 89, in <module>
    from simulation.simulation import Simulation
  File "simulation\simulation.pyc", line 18, in <module>
    manages all the action linked to a simulation, like running, saving, replay, etc...
  File "solver\assimuloSolver.pyc", line 7, in <module>
    Explicit solver to choose in the list of assimulo solvers:
  File "assimulo\solvers\__init__.pyc", line 25, in <module>
  File "assimulo\solvers\kinsol.pyc", line 12, in <module>
  File "assimulo\solvers\kinsol.pyc", line 10, in __load
  File "kinsol.pyx", line 1, in init assimulo.solvers.kinsol (assimulo\solvers\kinsol.c:19711)
ImportError: No module named algebraic

这里 qe 可以看到是第 7 行产生了我的麻烦,而这一行是

from assimulo.solvers import Radau5DAE

py2exe 的 setup.py 文件如下所示:

from distutils.core import setup
from py2exe.build_exe import py2exe
import sys
from glob import glob
import matplotlib

data_files = [("Microsoft.VC90.CRT", glob(r'C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*'))]
data_files.extend(matplotlib.get_py2exe_datafiles())
sys.path.append("C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")

excludes = ['_gtkagg', '_tkagg']
includes = [
            "scipy.sparse.csgraph._validation", 
            "scipy.special._ufuncs_cxx", 
            ]

opts = {
    "py2exe": {
        "includes":includes,
        "excludes":excludes,
    }
}

setup(name = "MySoft", 
      version = "0.1", 
      data_files=data_files, 
      windows=[{"script":"main.py"}], options=opts)

如果有人有线索,我会很感兴趣。谢谢

4

2 回答 2

0

有时我发现 py2exe 无法包含包,即使在包选项中列出,但发现如果我在 setup.py 中导入包,它开始工作,所以尝试在顶部附近添加setup.py

import assimulo

你有时会发现,即使

if False:
    import assimulo

会起作用,(使用它会assimulo在导入时进行很多设置)。

于 2014-11-19T09:47:21.910 回答
0

我的问题的解决方案是通过在包含选项中以这种方式添加代数包来获得的:

includes = ["assimulo.algebraic"]

还必须确保将库添加到 PATH 变量中。如果没有,可以简单地添加 sys.path.append("path to the library"),在我的例子中是

sys.path.append("C:\\Python27\\Lib\\site-packages\\assimulo")

在设置文件中

感谢您的帮助干杯

于 2014-11-19T11:16:23.210 回答