How do I set PYTHONPATH variable when installing MATLAB Engine API for Python in Nondefault Locations
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I don't have write permissions for both the MATLAB folder and the default Python folder, so I followed the instructions under "Build and Install in Nondefault Folders" on the tutorial Install MATLAB Engine API for Python in Nondefault Locations. I typed in the command to build and install the engine API with builddir="~/MATLAB_Engine_API/build" and installdir="~/MATLAB_Engine_API/install". I get the following output:
running build
running build_py
creating ~/MATLAB_Engine_API/build/lib
creating ~/MATLAB_Engine_API/build/lib/matlab
copying dist/matlab/mlarray.py -> ~/MATLAB_Engine_API/build/lib/matlab
copying dist/matlab/mlexceptions.py -> ~/MATLAB_Engine_API/build/lib/matlab
copying dist/matlab/__init__.py -> ~/MATLAB_Engine_API/build/lib/matlab
creating ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/matlabengine.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/enginesession.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/engineerror.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/enginehelper.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/futureresult.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/basefuture.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/fevalfuture.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/__init__.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
copying dist/matlab/engine/matlabfuture.py -> ~/MATLAB_Engine_API/build/lib/matlab/engine
creating ~/MATLAB_Engine_API/build/lib/matlab/_internal
copying dist/matlab/_internal/mlarray_utils.py -> ~/MATLAB_Engine_API/build/lib/matlab/_internal
copying dist/matlab/_internal/__init__.py -> ~/MATLAB_Engine_API/build/lib/matlab/_internal
copying dist/matlab/_internal/mlarray_sequence.py -> ~/MATLAB_Engine_API/build/lib/matlab/_internal
running install
running install_lib
creating ~/MATLAB_Engine_API/install/lib
creating ~/MATLAB_Engine_API/install/lib/python2.7
creating ~/MATLAB_Engine_API/install/lib/python2.7/site-packages
creating ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab
copying ~/MATLAB_Engine_API/build/lib/matlab/mlarray.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab
copying ~/MATLAB_Engine_API/build/lib/matlab/mlexceptions.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab
copying ~/MATLAB_Engine_API/build/lib/matlab/__init__.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab
creating ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/matlabengine.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/enginesession.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/engineerror.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/enginehelper.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/futureresult.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/basefuture.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/fevalfuture.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/__init__.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/matlabfuture.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
copying ~/MATLAB_Engine_API/build/lib/matlab/engine/_arch.txt -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine
creating ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal
copying ~/MATLAB_Engine_API/build/lib/matlab/_internal/mlarray_utils.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal
copying ~/MATLAB_Engine_API/build/lib/matlab/_internal/__init__.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal
copying ~/MATLAB_Engine_API/build/lib/matlab/_internal/mlarray_sequence.py -> ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/mlarray.py to mlarray.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/mlexceptions.py to mlexceptions.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/__init__.py to __init__.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/matlabengine.py to matlabengine.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/enginesession.py to enginesession.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/engineerror.py to engineerror.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/enginehelper.py to enginehelper.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/futureresult.py to futureresult.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/basefuture.py to basefuture.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/fevalfuture.py to fevalfuture.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/__init__.py to __init__.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine/matlabfuture.py to matlabfuture.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal/mlarray_utils.py to mlarray_utils.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal/__init__.py to __init__.pyc
byte-compiling ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/_internal/mlarray_sequence.py to mlarray_sequence.pyc
running install_egg_info
Writing ~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlabengineforpython-R2018a-py2.7.egg-info
It seems to give good output. I then tried to update the PYTHONPATH variable with
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/install/"
but then when I get into a python interpreter and try "import matlab" I get the error:
Python 2.7.15 (default, May 22 2018, 15:52:01)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matlab
I'm running python 2.7.15, so I don't think the version is incompatible. I tried adjusting the path the following ways but I still get the same error.
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/"
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/install/lib/"
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/install/lib/python2.7/"
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/install/lib/python2.7/site-packages/"
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab"
export PYTHONPATH="${PYTHONPATH}:~/MATLAB_Engine_API/install/lib/python2.7/site-packages/matlab/engine"
What is the issue with what I am doing?
I'm using MATLAB R2018b (9.5.0.944444) 64-bit (glnxa64), python 2.7.15 on a GNU/Linux operating system under release 3.10.0-957.5.1.el7.x86_64.
0 comentarios
Respuestas (2)
Karun Mathiazhagan
el 30 de Mayo de 2019
Hello Bryce,
The Python version does seem to be supported based upon the documentation page linked below:
But on a very cursory look, I feel that perhaps it is not possible to import the "matlab" package itself.
Have you tried the following recommended commands to start the engine as per the documentation page here:
import matlab.engine
eng = matlab.engine.start_matlab()
I hope this helps.
Best,
Karun
2 comentarios
Alan Frankel
el 21 de Mayo de 2020
Editada: Alan Frankel
el 21 de Mayo de 2020
(1) The thing you want in your PYTHONPATH is the parent directory of
matlab/engine/...
In your case, this is the path you want in your PYTHONPATH:
~/MATLAB_Engine_API/install/lib/python2.7/site-packages/
and not any of the other paths you mentioned.
(2) Do you know that the value of PYTHONPATH is what you think it is? What do you get if you type this command?
echo $PYTHONPATH
Note that if you do not already have PYTHONPATH set to a (nonempty) value, executing this command:
export PYTHONPATH="${PYTHONPATH}:foo/"
will set PYTHONPATH to this:
:foo/
which starts with a colon, so it is not what you want. If you do not already have PYTHONPATH set, or if it's empty, you should do this instead:
export PYTHONPATH="foo/"
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing 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!