Why would py.importl​ib.import_​module('ke​ras') fail?

조회 수: 7(최근 30일)
Dominik Mattioli
Dominik Mattioli 2019년 6월 18일
댓글: Dominik Mattioli 2020년 4월 14일
% Specify Python Executable Library.
pcPythonExe = 'C:\Users\dmattioli\AppData\Local\Programs\Python\Python37\python.exe';
[ver, exec, loaded] = pyversion(pcPythonExe);
% Ensure python-matlab integration code is on matlab path.
pyFolder = fullfile(matlabroot, 'toolbox', 'matlab', 'external', 'interfaces', 'python');
insert(py.sys.path, int64(0), pyFolder);
% Add relevant libaries' directory to python path.
otherpyFolder = 'C:\Users\dmattioli\.PyCharm2019.1\system\python_stubs\278535617';
insert(py.sys.path, int64(0), otherpyFolder)
>> pyversion
version: '3.7'
executable: 'C:\Users\dmattioli\AppData\Local\Programs\Python\Python37\python.exe'
library: 'C:\Users\dmattioli\AppData\Local\Programs\Python\Python37\python37.dll'
home: 'C:\Users\dmattioli\AppData\Local\Programs\Python\Python37'
isloaded: 1
The error occurs in the following code (test3):
test0 = py.importlib.import_module('numpy') % Succeeds
test1 = py.importlib.import_module('matplotllib') % Succeeds
test2 = py.importlib.import_module('tensorflow') % Succeeds
test3 = py.importlib.import_module('keras') % Fails
>> test3 = py.importlib.import_module('keras')
Error using __init__><module> (line 88)
Python Error: AttributeError: 'NoneType' object has no attribute 'write'
Error in conv_utils><module> (line 9)
from .. import backend as K
Error in __init__><module> (line 6)
from . import conv_utils
Error in __init__><module> (line 3)
from . import utils
Error in <frozen importlib>_call_with_frames_removed (line 219)
Error in <frozen importlib>exec_module (line 728)
Error in <frozen importlib>_load_unlocked (line 677)
Error in <frozen importlib>_find_and_load_unlocked (line 967)
Error in <frozen importlib>_find_and_load (line 983)
Error in <frozen importlib>_gcd_import (line 1006)
Error in __init__>import_module (line 127)
return _bootstrap._gcd_import(name[level:], package, level)
  댓글 수: 2
Dominik Mattioli
Dominik Mattioli 2020년 4월 14일
No, unfortunately not. I believe it is/was an issue with the MATLAB version that I was using (2018a?), where MATLAB had not yet implemented a capability for the type of layers that I was trying to use. It may be fixed with the newer version (2020a).

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

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

Start Hunting!

Translated by