PyTorch Compatibility Issue with MATLAB Engine

8 views (last 30 days)
I'm trying to use MATLAB Engine to extract features for a PyTorch model, but I'm receiving the following error.
File "xxxx", line 22, in <module>
import torch
File "/home/lab/anaconda3/lib/python3.6/site-packages/torch/__init__.py", line 81, in <module>
from torch._C import *
ImportError: /usr/local/MATLAB/R2019b/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by /home/lab/anaconda3/lib/python3.6/site-packages/torch/lib/libtorch_python.so)
Interestingly, the error occurs on the line where I try to import PyTorch, not where I import MATLAB Engine. I was previously able to import PyTorch prior to installing MATLAB Runtime. I'm running Ubuntu 16.04.
Any ideas on what I'm doing wrong?

Accepted Answer

Kevin Chu
Kevin Chu on 31 Dec 2020
It turns out that this was not a MATLAB-specific issue, but rather an issue with PyTorch. I upgraded the CUDA version but did not re-install PyTorch. I solved this problem by upgrading to a newer version of PyTorch.
  1 Comment
Yushi Liu
Yushi Liu on 4 Feb 2021
Upgrading torch did not work for me.
I solved the issue by switching the order of imports, i.e., importing torch first gives me errors but importing matlab.engine prior to importing torch worked without errors.
Kevin, do you want to help us with this? Switch the order of imports, and see if you can import the two in both order, with the latest torch release. Thanks in advance.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!