Unable to import Tensorflow, keras libraries using python interface in Matlab
Show older comments
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
chaitanya gogineni
on 13 Dec 2019
Elif Ecem Bas
on 2 Mar 2020
I really wonder wether this issue solved or not?
Nitesh Kumar
on 4 Aug 2020
@Chaitanya, Were you able to solve this issue?
Shantak Singh
on 14 Aug 2020
I also face the same issue
yassine kebbati
on 30 Sep 2020
no one found a solution to this?
Abdelwahab Afifi
on 14 Feb 2021
any solution?
Answers (1)
Patrick Staehli
on 6 Jan 2021
1 vote
Just start matlab from the anaconda console by typing matlab
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!