- the class matlab.exception.PyException isn't found
- import of lxml
MATLAB <-> Python problem with import of lxml
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello community,
I have strange troubles when calling Python functions from MATLAB. It seems that importing some libraries cause problems.
I use Python 2.7 and have lxml for Python installed (PyPI). MATLAB version is currently 2014b.
The in MATLAB non-working Python function (filename is test.py):
from lxml import etree
def test():
return 'This was an include test'
returns the following output when I try to include and run in MATLAB:
>>insert(py.sys.path,int32(0),pwd)
>> py.test.test
Undefined variable "py" or function "py.test.test".
>> py.importlib.import_module('test')
Error using py.importlib.import_module
The class 'matlab.exception.PyException' contains a parse error, cannot
be found on MATLAB's search path, or is shadowed by another file with
the same name.
If the import line in the Python file is commented out:
# from lxml import etree
def test():
return 'This was an include test'
Everything is fine in MATLAB (I did not forget to restart MATLAB):
>> insert(py.sys.path,int32(0),pwd)
>> py.test.test
ans =
Python str with no properties.
This was an include test
>> py.importlib.import_module('test')
ans =
Python module with properties:
test: [1x1 py.function]
<module 'test' from 'C:\XXXXXXXXXXXXXXXXXX\test.py'>
Within Python both versions of the Python function "test" work.
I have the same/similar problem with a vendor delivered Python module for accessing some specialized communication hardware.
I think that both problems are related. All Python programs work from IDLE or command line, but they do not within MATLAB.
Does anyone have a clue?
Thanks! Markus
0 comentarios
Respuestas (2)
Robert Snoeberger
el 20 de Mayo de 2015
Editada: Robert Snoeberger
el 20 de Mayo de 2015
It looks like you have two problems:
This answer is only for the first problem. The error message "The class 'matlab.exception.PyException' contains a parse error, cannot be found on MATLAB's search path, or is shadowed by another file with the same name." isn't good. This indicates a problem with your path. I've seen an answer to another question where the solution was to reinstall MATLAB. See here .
0 comentarios
Markus
el 22 de Mayo de 2015
3 comentarios
Robert Snoeberger
el 31 de Mayo de 2015
Hi Markus,
I have an update on problem 2. I was able to import lxml.etree in MATLAB when using WinPython 2.7.9.5. The WinPython distribution bundles lxml.
I looked at etree.pyd with dependency walker. In this case, dependency walker was able to find MSVCR90.DLL. The other DLLs you mentioned, however, were not found. In the WinPython installation, I found MSVCR90.DLL at the following location.
WinPython-32bit-2.7.9.5\python-2.7.9\msvcr90.dll
Two other DLLs were with it, MSVCM90.dll and MSVCP90.dll.
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!