Unable to import Tensorflow, keras libraries using python interface in Matlab

24 views (last 30 days)
Hello Everyone,
I created a conda vitual environment and installed tensorflow 2.0. I am using Matlab 2018b version. I am able to import other libraries such as numpy, pandas, scikit-learn. but unable to import tensorflow 2.0 using py.importlib.import_module('tensorflow') command and got the below mentioned error:
Error using __init__><module> (line 40)
Python Error: ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not
a package
Error in __init__><module> (line 98)
from tensorflow_core import *
Error in <frozen importlib>_call_with_frames_removed (line 219)
Error in <frozen importlib>exec_module (line 678)
Error in <frozen importlib>_load_unlocked (line 665)
Error in <frozen importlib>_find_and_load_unlocked (line 955)
Error in <frozen importlib>_find_and_load (line 971)
Error in <frozen importlib>_gcd_import (line 994)
Error in __init__>import_module (line 126)
return _bootstrap._gcd_import(name[level:], package, level)
As a workaround, I created a new virtual environment and installed tensorflow 1.2.1 and keras 1.0.7. tensorflow 1.2.1 is getting imported in matlab but getting the below mentioned error while trying to import keras 1.0.7:
>> py.importlib.import_module('keras')
Error using __init__><module> (line 60)
Python Error: AttributeError: 'NoneType' object has no attribute 'write'
Error in __init__><module> (line 2)
from . import backend
Error in <frozen importlib>_call_with_frames_removed (line 219)
Error in <frozen importlib>exec_module (line 678)
Error in <frozen importlib>_load_unlocked (line 665)
Error in <frozen importlib>_find_and_load_unlocked (line 955)
Error in <frozen importlib>_find_and_load (line 971)
Error in <frozen importlib>_gcd_import (line 994)
Error in __init__>import_module (line 126)
return _bootstrap._gcd_import(name[level:], package, level)
Kindly someone help me in fixing the issue.
Thanks & Regards,
Chaitanya Gogineni
  6 Comments

Sign in to comment.

Answers (1)

Patrick Staehli
Patrick Staehli on 6 Jan 2021
Just start matlab from the anaconda console by typing matlab

Community Treasure Hunt

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

Start Hunting!