导入matlab.engine而不在ubuntu16.04上的python3.5.2中导入matplotlib时发生错误。为什么?

时间:2017-12-19 03:31:55

标签: python matlab matplotlib jupyter-notebook ubuntu-16.04

我在ubuntu16.04上的python(3.5.2)中使用matlab.engine(MATLAB R2016b), 遵循官方指示"MATLAB API for Python"

面对这个奇怪的问题,我感到很困惑。

导入matlab.engine后导入matplotlib时效果很好:

import matplotlib
import matlab.engine
eng = matlab.engine.start_matlab()
#...

但是,如果没有先导入matplotlib,则jupyter-notebook中会出现以下错误:

---------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/workspace/python/vp3.5_64/lib/python3.5/site-packages/matlab/engine
/__init__.py in <module>()
     41 try:
---> 42     pythonengine = 
importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
     43 except:

~/workspace/python/vp3.5_64/lib/python3.5/importlib/__init__.py in 
import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_gcd_import(name, package, level)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_find_and_load(name, import_)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_find_and_load_unlocked(name, import_)

ImportError: No module named 'matlabengineforpython3_5'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
~/workspace/python/vp3.5_64/lib/python3.5/site-packages/matlab/engine
/__init__.py in <module>()
     57                 os.environ[_envs[_arch]] = _bin_dir
---> 58         pythonengine = 
importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
     59     except Exception as e:

~/workspace/python/vp3.5_64/lib/python3.5/importlib/__init__.py in 
import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_gcd_import(name, package, level)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_find_and_load(name, import_)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_find_and_load_unlocked(name, import_)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_load_unlocked(spec)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
module_from_spec(spec)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap_external.py 
in create_module(self, spec)

~/workspace/python/vp3.5_64/lib/python3.5/importlib/_bootstrap.py in 
_call_with_frames_removed(f, *args, **kwds)

ImportError: /home/andy/Matlab/R2016b/extern/engines/python/dist/matlab
/engine/glnxa64/../../../../../../../bin/glnxa64/libssl.so.1.0.0: 
undefined symbol: EVP_idea_cbc

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-1-454d0b551a51> in <module>()
----> 1 import matlab.engine
      2 
      3 

~/workspace/python/vp3.5_64/lib/python3.5/site-packages/matlab/engine
/__init__.py in <module>()
     59     except Exception as e:
     60         raise EnvironmentError('Please reinstall MATLAB Engine for 
Python or contact '
---> 61    'MathWorks Technical Support for assistance: %s' % e)
     62 
     63 

OSError: Please reinstall MATLAB Engine for Python or contact MathWorks
Technical Support for assistance: /home/andy/Matlab/R2016b/extern/engines
/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64
/libssl.so.1.0.0: undefined symbol: EVP_idea_cbc

此外,从终端运行.py文件时会显示类似的错误消息:

Traceback (most recent call last):
File "/home/andy/workspace/python/vp3.5_64/lib/python3.5/site-packages
/matlab/engine/__init__.py", line 42, in <module> 
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
  File "/home/andy/workspace/python/vp3.5_64/lib/python3.5/importlib
/__init__.py", line 126, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in 
_find_and_load_unlocked
ImportError: No module named 'matlabengineforpython3_5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/andy/workspace/python/vp3.5_64/lib/python3.5/site-packages
/matlab/engine/__init__.py", line 58, in <module>
    pythonengine = 
importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
  File "/home/andy/workspace/python/vp3.5_64/lib/python3.5/importlib
/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in 
create_module
  File "<frozen importlib._bootstrap>", line 222, in 
_call_with_frames_removed
ImportError: /home/andy/Matlab/R2016b/extern/engines/python/dist/matlab
/engine/glnxa64/../../../../../../../bin/glnxa64/libssl.so.1.0.0: 
undefined symbol: EVP_idea_cbc

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test2.py", line 4, in <module>
    from community_detectors import *
  File "/home/andy/workspace/paper0/community_detectors.py", line 11, in 
<module>
    from cd_elm import cd_elm
  File "/home/andy/workspace/paper0/cd_elm.py", line 6, in <module>
    import matlab.engine
  File "/home/andy/workspace/python/vp3.5_64/lib/python3.5/site-packages
/matlab/engine/__init__.py", line 61, in <module>
    'MathWorks Technical Support for assistance: %s' % e)
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks 
Technical Support for assistance: /home/andy/Matlab/R2016b/extern/engines
/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64
/libssl.so.1.0.0: undefined symbol: EVP_idea_cbc

为什么?

导入matplotlib似乎包含了名为'matlabengineforpython3_5'的缺失模块?这是真的吗?

matplotlibmatlab.engine之间的关系是什么?

有没有更好的方法来解决这个导入问题?

谢谢:)

0 个答案:

没有答案