简体   繁体   English

从 Python 虚拟环境调用 matlab

[英]Call matlab from a Python virtual environment

I can call MATLAB from my system python:我可以从我的系统 python 调用 MATLAB:

>>> 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.我已经为系统 python 和我的虚拟环境运行了setup.py 安装说明

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.我预期的问题像这样的,在我所设置DYLD_LIBRARY_PATH明确地将解决的事情,但我没有那个环境变量设置时,我跑我的系统蟒蛇。

What could be different between the two python implementations that would cause this segfault?导致此段错误的两个 python 实现之间可能有什么不同?

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).编辑:我在 2013 年末的 13" Macbook Pro 上使用 OS X Yosemite。我在新安装的虚拟环境(不是虚拟机)中使用 Python 2.7。

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.其中installdir是我的 virtualenv, matlabroot是 MatLab 安装的目录。

Seems to work with my windows server, so far, so good.到目前为止,似乎可以与我的 Windows 服务器一起使用,非常好。

Reference here:参考这里:

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

I ran the " python setup.py install " from matlabroot\\extern\\engines\\python with my virtual environment active.我在我的虚拟环境处于活动状态时从matlabroot\\extern\\engines\\python运行“ python setup.py install ”。 Note that I did use venv .请注意,我确实使用了venv

I have successfully run Matlab 2019b through venv.我已经通过 venv 成功运行了 Matlab 2019b。 The command that I used: sudo python3.7 setup.py install --prefix="/home/ubuntu/alexandros/vitrualEnv/py37我使用的命令: 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/ .就我而言,它是/home/ubuntu/alexandros/vitrualEnv/py37/ Inside the virtual environment, you will see在虚拟环境里面,你会看到

图片

Then you have to go inside the lib and choose the version that you have installed.然后你必须进入 lib 并选择你已经安装的版本。 For instance, mine was 3.7 and that's why I have python3.7 instead of python3.例如,我的是 3.7,这就是为什么我使用 python3.7 而不是 python3。 You might have several python folders inside the lib folder like:您可能在 lib 文件夹中有几个 python 文件夹,例如:

图片

However, you have to use the one that is the main.但是,您必须使用主要的那个。 Inside this folder you will see something similar to this:在此文件夹中,您将看到类似于以下内容的内容:

图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM