我正在尝试使用py2exe在使用库assimulo(微分方程求解器)的软件上构建可执行文件。遇到的问题是,在执行过程中我收到:
导入错误:没有名为代数的模块
确切的错误消息是:
Traceback (most recent call last):
File "main.py", line 89, in <module>
from simulation.simulation import Simulation
File "simulationsimulation.pyc", line 18, in <module>
manages all the action linked to a simulation, like running, saving, replay, etc...
File "solverassimuloSolver.pyc", line 7, in <module>
Explicit solver to choose in the list of assimulo solvers:
File "assimulosolvers__init__.pyc", line 25, in <module>
File "assimulosolverskinsol.pyc", line 12, in <module>
File "assimulosolverskinsol.pyc", line 10, in __load
File "kinsol.pyx", line 1, in init assimulo.solvers.kinsol (assimulosolverskinsol.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.0VCredistx86Microsoft.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)
如果有人有线索,我会很感兴趣。谢谢
有时我发现py2exe无法包含软件包,即使在软件包选项中列出,但发现如果我在 setup.py 中导入软件包,它就会开始工作,因此请尝试在setup.py
顶部附近添加:
import assimulo
你有时会发现,即使
if False:
import assimulo
将起作用,(使用它assimulo
在导入时进行大量设置)。
我的问题的解决方案是通过在 include 选项中添加代数包来获得的:
includes = ["assimulo.algebraic"]
还必须确保将库添加到 PATH 变量中。如果没有,可以简单地添加sys.path.append("库路径"),在我的例子中是
sys.path.append("C:\Python27\Lib\site-packages\assimulo")
在安装文件中
感谢您的帮助干杯