安装问题" MATLAB Engine for Python"与Anaconda

时间:2015-10-27 00:02:43

标签: python macos matlab anaconda

我正在使用Python 3.4.3 | OS X 10.10.5和these instructions to install MATLAB Engine for Python之后的Anaconda 2.3.0(x86_64)。安装似乎成功,但启动python&试图导入,我看到以下内容:

Python 3.4.3 |Anaconda 2.3.0 (x86_64)| (default, Oct 20 2015, 14:27:51) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
Traceback (most recent call last):
  File "/Users/tyler/.local/lib/python3.4/site-packages/matlab/engine/__init__.py", line 42, in <module>
    pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
  File "/Users/tyler/anaconda/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'matlabengineforpython3_4'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/tyler/.local/lib/python3.4/site-packages/matlab/engine/__init__.py", line 58, in <module>
    pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
  File "/Users/tyler/anaconda/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1715, in load_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
ImportError: dlopen(/Applications/MATLAB_R2015b.app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython3_4.so, 2):     Library not loaded: @rpath/libpython3.4m.dylib    
  Referenced from: /Applications/MATLAB_R2015b    .app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython3_4.so    
  Reason: image not found    

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tyler/.local/lib/python3.4/site-packages/matlab/engine/__init__.py", line 60, in <module>
    raise EnvironmentError('The installation of MATLAB Engine for Python is '
OSError: The installation of MATLAB Engine for Python is corrupted.  Please reinstall it or contact MathWorks Technical Support for assistance.

在研究此问题时,我在MathWorks上找到了several other references这个确切的问题&#39;网站,都没有决议。最后一个链接表明问题可能出在dynamic linking

鉴于有多少科学工具箱仅在MATLAB中可用,能够使用Anaconda调用此引擎将非常有用。虽然还有其他可用的软件包支持此功能,但它们总是存在限制或其他复杂性,如客户端 - 服务器体系结构。

欢迎任何建议。

2 个答案:

答案 0 :(得分:2)

根据我与MathWorks支持的沟通,MATLAB Engine for Python与Anaconda不兼容。幸运的是,这是不正确的。

感谢Anaconda邮件列表的一些指示,我找到了一个简单的解决方案:

sudo ln -s ~/anaconda/lib/libpython3.4m.dylib /usr/lib

在此之后,matlab.engine导入成功。希望这有助于某人!

编辑:从OS X 10.11 El Capitan开始,需要根据Rootless功能调整解决方法,因为root不再具有修改/ usr / lib的权限

sudo ln -s ~/anaconda/lib/libpython3.4m.dylib /usr/local/lib

答案 1 :(得分:0)

如果您要在conda环境中安装matlab引擎,请执行以下步骤:

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

例如

cd /opt/MATLAB/R2019a/extern/engines/python
python setup.py install --prefix="/home/nagabhushan/anaconda3/"

现在,matlab引擎软件包实际上是单独安装的 anaconda3/lib/python3.6/site-package/matlab
因此,您需要将那个matlab文件夹手动移动到python正在使用的site-package文件夹中。如果您有多个虚拟环境,请将其移至将要运行程序的虚拟环境的相应站点软件包文件夹。 例如 anaconda3/envs/my_env/lob/python3.6/site-packages/matlab

参考文献:
https://stackoverflow.com/a/41800724/3337089
https://stackoverflow.com/a/56553740/3337089