3

I can call MATLAB from my system python:

>>> import matlab.engine
>>> 

but when I load a virtual environment, I now get a segfault:

>>> import matlab.engine
Segmentation fault: 11

I've run the setup.py install instructions for both system python and my virtual environment.

I expected questions like this one, in which I have to set the DYLD_LIBRARY_PATH explicitly would fix things, but I don't have that environment variable set when I run my system python.

What could be different between the two python implementations that would cause this segfault?

EDIT: I'm using OS X Yosemite on a Late 2013 13" Macbook Pro. I'm using Python 2.7 from a freshly installed virtual environment (NOT a virtual machine).

paisanco
  • 4,098
  • 6
  • 27
  • 33
Nick Sweet
  • 2,030
  • 3
  • 31
  • 48

3 Answers3

1

I did this:

cd "matlabroot\extern\engines\python"
python setup.py install --prefix="installdir"

Where the installdir is my virtualenv, matlabroot the directory for the MatLab install.

Seems to work with my windows server, so far, so good.

Reference here:

https://www.mathworks.com/help/matlab/matlab_external/install-matlab-engine-api-for-python-in-nondefault-locations.html

acidtobi
  • 1,375
  • 9
  • 13
  • Try to to format your answer/code to make it more legible. – M-- Apr 17 '17 at 20:11
  • Anyone get this to work on macOS? macOS seems to always want to use [`mwpython`](https://www.mathworks.com/help/compiler_sdk/python/mwpython.html) which I can't figure out how to get working with `venv`. – phoenix Jan 18 '19 at 12:03
0

I ran the "python setup.py install" from matlabroot\extern\engines\python with my virtual environment active. Note that I did use venv.

Sid Mhatre
  • 3,272
  • 1
  • 19
  • 38
0

I have successfully run Matlab 2019b through venv. The command that I used: sudo python3.7 setup.py install --prefix="/home/ubuntu/alexandros/vitrualEnv/py37

You have to give the path to the full environment. In my case, it is /home/ubuntu/alexandros/vitrualEnv/py37/. Inside the virtual environment, you will see

image

Then you have to go inside the lib and choose the version that you have installed. For instance, mine was 3.7 and that's why I have python3.7 instead of python3. You might have several python folders inside the lib folder like:

image

However, you have to use the one that is the main. Inside this folder you will see something similar to this:

image

Timus
  • 10,974
  • 5
  • 14
  • 28