Matlab Engine Python - iPython 出现 OSx Anaconda Segfault 或 DYLD_LIBRARY_PATH 错误

Int*_*eat 5 python macos matlab matlab-engine anaconda

在终端中安装 matlab python 包后,使用:

cd "matlabroot\extern\engines\python"
python setup.py install
Run Code Online (Sandbox Code Playgroud)

尝试运行它时,出现段错误:

:~$ python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import matlab.engine
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)

但是,我可以通过设置 DYLD_LIBRARY_PATH 来解决这个问题,然后 matlab.engine 就可以工作:

:~$ export DYLD_LIBRARY_PATH=/System/Library/Frameworks/Python.framework/Versions/Current/lib:$DYLD_LIBRARY_PATH
:~$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
>>> eng = matlab.engine.start_matlab()
>>> exit()
Run Code Online (Sandbox Code Playgroud)

但是,当我随后尝试启动 iPython 时,出现此错误:

Traceback (most recent call last):
  File "//anaconda/bin/ipython", line 4, in <module>
    from IPython import start_ipython
  File "//anaconda/lib/python2.7/site-packages/IPython/__init__.py", line 45, in <module>
    from .config.loader import Config
  File "//anaconda/lib/python2.7/site-packages/IPython/config/__init__.py", line 6, in <module>
    from .application import *
  File "//anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 19, in <module>
    from IPython.config.configurable import SingletonConfigurable
  File "//anaconda/lib/python2.7/site-packages/IPython/config/configurable.py", line 12, in <module>
    from .loader import Config, LazyConfigValue
  File "//anaconda/lib/python2.7/site-packages/IPython/config/loader.py", line 16, in <module>
    from IPython.utils.path import filefind, get_ipython_dir
  File "//anaconda/lib/python2.7/site-packages/IPython/utils/path.py", line 14, in <module>
    import tempfile
  File "//anaconda/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "//anaconda/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(//anaconda/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
  Referenced from: //anaconda/lib/python2.7/lib-dynload/_io.so
  Expected in: dynamic lookup
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,Python 版本是不同的。我认为这是我的系统 Python 和 Anaconda 之间的冲突,但我不知道如何修复它,非常感谢任何帮助。谢谢。

bik*_*ule 0

您需要使用 conda 命令行安装实用程序安装库,而不是 python。conda help search并且conda help install应该让你继续前进。