py2exe and assimulo - No module named algebraic - python

I am trying to build an executable using py2exe on a soft that uses the library assimulo (differential equation solver). The problem encountered is that during execution I receive:
ImportError: No module named algebraic
The exact error message is:
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
Here qe can see that it is line 7 that produces my troubles, and this line is
from assimulo.solvers import Radau5DAE
the setup.py file for py2exe looks like the following:
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)
If someone has a clue, I would be very interested.
Thanks

Sometimes I have found py2exe failing to include packages, even when listed in the packages option, but have found that if I import the package in setup.py it starts to work so try adding, near the top of setup.py:
import assimulo
You will sometimes find that even
if False:
import assimulo
will work, (use this is assimulo does a lot of setting up on import).

The solution to my problem was obtained by adding, in the includes option, the algebraic package this way:
includes = ["assimulo.algebraic"]
One must also be sure that the library is added to the PATH variable. If not, one can simply add sys.path.append("path to the library"), which in my case was
sys.path.append("C:\\Python27\\Lib\\site-packages\\assimulo")
in the setup file
Thanks for the help
Cheers

Related

Packaging a python application ( with enthought, matplotlib, wxpython) into executable

My Python 2.7 application uses matplotlib, enthought (mayavi, traits), wxpython libraries. I need to package it into an executable on Windows, which, after some research and experimenting seems like a not straightforward task.
I have so far experimented with PyInstaller and bbfreeze. In both of them I specify hidden imports/includes (which I could gather fromrandom information on the web) to import the Enthought packeges. Both manage to create an executable (for bbfreeze I excluded the matplotlib part of my application so far), but when I run it, both return the same error:
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "__main__.py", line 128, in <module>
File "__main__test__.py", line 23, in <module>
File "traitsui/api.py", line 36, in <module>
File "traitsui/editors/__init__.py", line 23, in <module>
File "traitsui/editors/api.py", line 49, in <module>
File "traitsui/editors/table_editor.py", line 37, in <module>
File "traitsui/table_filter.py", line 35, in <module>
File "traitsui/menu.py", line 128, in <module>
File "pyface/toolkit.py", line 98, in __init__
NotImplementedError: the wx pyface backend doesn't implement MenuManager
Any ideas what should I do? Alternatively has anyone had experience with creating such an executable and can recommend a tool or method ? So far I have seen only this tutorial but it uses py2exe and apparently requires downloading the whole ETS - if nothing else gonna give it a try...
Here is the solution which worked for me.
I have tried to use bbfreeze, PyInstaller , py2exe and cx_Freeze. In the end I decided to go with cx_Freeze as it is apparently popular with people who are packaging the applications with enthought classes.
With cx_Freeze I got the similar error message as above. The problem is that it saves the necessary modules in "library.zip" file, which is something that enthought classes including mayavi have problem with. Fortunately cx_Freeze allows specifying "create_shared_zip": False option, which then makes it so that source files are directly copied into the build directory as they are, instead of in a zip file.
Additionally, I have found that some Enthought files and folders have to be manually included in include_files (same goes for scipy, source: here). After this it worked. I add my setup file code below, hope it helps.
import sys
import os
from cx_Freeze import setup, Executable
import scipy
scipy_path = os.path.dirname(scipy.__file__) #use this if you are also using scipy in your application
build_exe_options = {"packages": ["pyface.ui.wx", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_tkagg"],
"excludes": ['numarray', 'IPython'],
"include_files": [("C:\\Python27\\Lib\\site-packages\\tvtk\\pyface\\images\\", "tvtk\\pyface\\images"),
("C:\\Python27\\Lib\\site-packages\\pyface\\images\\", "pyface\\images"),
("C:\\Python27\\Lib\\site-packages\\tvtk\\plugins\\scene\\preferences.ini", "tvtk\\plugins\\scene\\preferences.ini"),
("C:\\Python27\\Lib\\site-packages\\tvtk\\tvtk_classes.zip", "tvtk\\tvtk_classes.zip"),
("C:\\Python27\\Lib\\site-packages\\mayavi\\core\\lut\\pylab_luts.pkl","mayavi\\core\\lut\\pylab_luts.pkl"),
("C:\\Python27\\Lib\\site-packages\\mayavi\\preferences\\preferences.ini","mayavi\\preferences\\preferences.ini"),
("C:\\Python27\\Lib\\site-packages\\numpy\\core\\libifcoremd.dll","numpy\\core\\libifcoremd.dll"),
("C:\\Python27\\Lib\\site-packages\\numpy\\core\\libmmd.dll","numpy\\core\\libmmd.dll"),
(str(scipy_path), "scipy") #for scipy
]
,"create_shared_zip": False #to avoid creating library.zip
}
executables = [
Executable('myfile.py', targetName="myfile.exe", base=None)
]
setup(name='myfile',
version='1.0',
description='myfile',
options = {"build_exe": build_exe_options},
executables=executables
)
Configuration:
python 2.7
altgraph==0.9
apptools==4.3.0
bbfreeze==1.1.3
bbfreeze-loader==1.1.0
configobj==5.0.6
cx-Freeze==4.3.3
Cython==0.23.4
matplotlib==1.4.3
mayavi==4.4.3
MySQL-python==1.2.5
natgrid==0.2.1
numpy==1.10.0b1
opencv-python==2.4.12
pandas==0.16.2
pefile==1.2.10.post114
Pillow==3.1.1
plyfile==0.4
psutil==4.1.0
pyface==5.0.0
Pygments==2.0.2
pygobject==2.28.6
pygtk==2.22.0
PyInstaller==3.1
pyparsing==2.0.3
pypiwin32==219
PySide==1.2.2
python-dateutil==2.4.2
pytz==2015.4
scipy==0.16.0
six==1.9.0
subprocess32==3.2.7
traits==4.5.0
traitsui==5.0.0
transforms3d==0.2.1
VTK==6.2.0

Why am I getting this ImportError?

I have a tkinter app that I am compiling to an .exe via py2exe.
In the setup file, I have set it to include lxml, urllib, lxml.html, ast, and math.
When I run python setup.py py2exe in a CMD console, it compiles fine. I then go to the dist folder It has created, and run the .exe file.
When I run the .exe I get this popup window.
(source: gyazo.com)
I then procede to open the Trader.exe.log file, and the the contents say the following;
Traceback (most recent call last):
File "Trader.py", line 1, in <module>
File "lxml\html\__init__.pyc", line 42, in <module>
File "lxml\etree.pyc", line 12, in <module>
File "lxml\etree.pyc", line 10, in __load
File "lxml.etree.pyx", line 84, in init lxml.etree (src\lxml\lxml.etree.c:190292)
ImportError: cannot import name _elementpath
Included here is a copy of my setup.py file.
Please help me find the problem here. Thanks in advance.
Looks like py2exe doesn't realize it should include the lxml._elementpath module, which is conditionally imported by lxml.etree. You can tell it to include that module explicitly with the includes keyword argument in your setup.py.
setup(
options={'py2exe': {"includes": ["lxml._elementpath"]}}
)
Py2exe has made documentation of this error on this page: http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
They also offer a working solution.

No module named weight_vector in sci with py2exe in windows

I get the following error message using Python v2.7.5 and scipy v0.12.0 with py2exe v0.6.9 on a 32 bit machine using 32 bit versions of the packages from Christoph Gohlke. If anyone can provide relevant and useful suggestions I would greatly appreciate it. Here is the error message:
Traceback (most recent call last):
File "MainWindow.py", line 13, in <module>
from svm.svm import SVM
File "svm\svm.pyc", line 4, in <module>
File "sklearn\svm\__init__.pyc", line 13, in <module>
File "sklearn\svm\classes.pyc", line 3, in <module>
File "sklearn\linear_model\__init__.pyc", line 20, in <module>
File "sklearn\linear_model\sgd_fast.pyc", line 12, in <module>
File "sklearn\linear_model\sgd_fast.pyc", line 10, in __load
File "weight_vector.pxd", line 14, in init sklearn.linear_model.sgd_fast
(sklearn\linear_model\sgd_fast.c:13206)
ImportError: No module named weight_vector
This is my setup.py file:
from distutils.core import setup
import py2exe
import sys
sys.path.append('../')
dcm = 'dcm.testDCM'
svm_path = 'svm.svm'
setup(windows=[{"script":"MainWindow.py"}],
options={"py2exe":{
"includes" : ["sip", dcm, svm_path,
'sklearn',
'scipy.sparse.csgraph._validation',
'sklearn.linear_model.sgd_fast.weight_vector']}})
Actually, I have solved the problem in this question scipy with py2exe problesm and solved it using the second answer in that question (the answer), adding the "scipy.sparse.csgraph._validation" in my includes options for the py2exe.
Then I want to do the similar thing for the error "No module named weight_vector", say, adding the "sklearn.linear_model.sgd_fast.weight_vector" in my includes options. However, it didn't work.
I check the directory "sklearn.linear_model.sgd_fast" only to find that the sgd_fast is a ".pyd" file rather than a .py file. Maybe this is why my methods cannot work.
I didn't get any idea about dealing with the pyd file. Have anybody met the similar problems or got any ideas? I really need your help.

Using kinterbasdb with py2exe

I'm trying to create executable program with py2exe. I get the following error message when kinterbasdb is imported:
Traceback (most recent call last):
File "AlarmReporter.py", line 13, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "kinterbasdb\__init__.pyo", line 119, in <module>
File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading kinterbasdb\_kinterbasdb.pyd
Here's my very basic setup.py for py2exe:
from distutils.core import setup
import py2exe
import sys
setup(
options={'py2exe': dict(bundle_files=1, optimize=2)},
console=['AlarmReporter.py'],
zipfile=None,
)
I'm having problem understanding the error message and have no idea how to fix it.
Try to exclude libfbclient dll
Error while transforming .py to .exe
If that doesn't work , try to use the new fdb driver (the future replacement of kinterbasdb)
http://permalink.gmane.org/gmane.comp.db.firebird.python/104
(it doesn't need compiling only the libfbclient.dll)
Another option is to use the pure driver that doesn't need no dll and no c generated binary
https://github.com/nakagami/pyfirebirdsql
But you will use it at your own risk ;)

Py2Exe Error: Win32com.client causes errors when trying to run created executable

My script that I'm trying to create into an executable contains the following imports:
import csv, time, BeautifulSoup, sys, mechanize, os, traceback, win32com.client as win32
My setup.py looks like this:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "tool.py"}],
zipfile = None,
)
The .exe of my program is created successfully, however when I try to run it I receive the following errors:
Traceback (most recent call last):
File "tool.py", line 1, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32com\__init__.pyc", line 5, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32api.pyd
Surprisingly, it compiles into an .exe fine if I use bundle_files: = 3 however I need this program to be in one executable, not multiple files. I've read this from the py2exe website but I'm not sure if that's what I need to do/use. If that is the answer I'm looking for, I don't know how to use that or what to do with it. Please explain.
Any help is greatly appreciated!
This was solved by upgrading to Python 2.7. I originally had Python 2.6 installed but the update solved this issue.

Categories