Matlab engine for python can not be installed if I don't have writing premissions

57 views (last 30 days)
Hi,
I am working on a cluster where I don't have writing permissions on the install folder of Matlab.
It looks like the only way to install the matlab engine for python is to run the command
python setup.py build -b BUILD_FOLDER bdist_egg -d DIST_FOLDER
This worked fine for older versions of Matlab, however, when I do it with Matlab R2022A and python 3.9 I keep getting
error: could not create 'dist/matlabengineforpython.egg-info': Permission denied
Because it looks like matlab is still trying to use the "dist" folder in the matlab installation directory.
Why such an undesirable behaviour? And how could I avoid it?
Thanks

Answers (1)

Ariel Lanza
Ariel Lanza on 15 Nov 2022
It looks like I could solve it.
Cause
It looks like the setup.py file is doing something really bad, i.e., accessing a folder regardless of the instructions it receives.
By looking at the code there are two points in which this might be done:
_cwd = os.getcwd()
...
_engine_dir = os.path.join(_cwd, _dist, _matlab_package, _engine_package)
_extern_bin_dir = os.path.join(_cwd, _parent, _parent, _parent, 'extern', 'bin')
Which means that _extern_bin_dir , and engine_dir (and other folders) depend on os.getcwd() (which is the folder in which we lauch setup.py)
The other point is
package_dir={'': 'dist'},
which sets dist as "package_dir.
Solution
I have created a folder in my home directory called temp. Its path is going to be ~/temp.
I have copied setup.py from the matlab installation folder and the dist folder, i.e.,
cp setup.py ~/temp/
cp -r dist ~/temp/dist
I have changed the parts that I didn't like in the following way
_engine_dir = os.path.join("FULL_PATH_OF_MY_HOME/temp", _dist, _matlab_package, _engine_package)
And
package_dir={'': 'FULL_PATH_OF_MY_HOME/dist'},
where "FULL_PAHT_OF_MY_HOME" is the actual path of my home
Finally, from the matlab installation folder I run
python ~/temp/setup.py build -b ~/temp/b bdist_egg -d ~/temp/d
which finally works and creates an egg file in ~/temp/d.
However, it is not so easy...
I then move to ~/temp/d
I convert the egg to a wheel and I install it with
wheel convert matlabengineforpython-R2022a-py3.9.egg
pip install matlabengineforpython-R2022a-py39-none-any.whl
And it is not finished. Since I used to have the issue raised here:
which is, I get
ImportError: MATLAB_FOLDER/R2022a/extern/engines/python/../../../extern/bin/glnxa64/../../../sys/os/glnxa64/libstdc++.so.6: undefined symbol: __cxa_thread_atexit_impl
However it could be solved with
export LD_PRELOAD="MATLAB_FOLDER/R2022a/bin/glnxa64/glibc-2.17_shim.so"
where "MATLAB_FOLDER" should be substituted with the location of your matlab folder.
Then I could enter and everything worked, i.e.,
$ python
Python 3.9.15
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
>>> eng = matlab.engine.start_matlab()
>>> eng.sqrt(1.1)
1.0488088481701516
>>> eng.quit()
>>> exit()
Comment
This is not a good solution, but the problem is with MATLAB.
1. I am just hoping that every file in dist does not rely on local paths. But who could tell? The fact that the ImportError relies so much on local paths is already worrying.
2. The file
MATLAB_FOLDER/R2022a/extern/engines/python/../../../extern/bin/glnxa64/../../../sys/os/glnxa64/libstdc++.so.6
Is the same as
MATLAB_FOLDER/R2022a/sys/os/glnxa64/libstdc++.so.6
3. It appears that in python eggs are deprecated and we should prefer wheels (see https://packaging.python.org/en/latest/discussions/wheel-vs-egg/ )
4. It appears that in python "new projects are advised to avoid setup.py configurations (beyond the minimal stub) when custom scripting during the build is not necessary." (see https://setuptools.pypa.io/en/latest/userguide/quickstart.html#setup-py )
5. It would be useful to know what do we have to do with this "LD_PRELOAD" variable, it looks like the only source of information about this variable is questions and answers here. No documentation at all in the Matlab engine for Python hints at those.
  1 Comment
Miguel Angel Alonso Calderon
I got the same error message. Try running the Command Prompt with Administrator rights. In my case I was able to install everything correctly.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!