- the class matlab.exception.PyException isn't found
- import of lxml
MATLAB <-> Python problem with import of lxml
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Robert Snoeberger
2015년 5월 20일
편집: Robert Snoeberger
2015년 5월 20일
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
Markus
2015년 5월 22일
댓글 수: 3
Robert Snoeberger
2015년 5월 31일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!