title: how to fix "import keras not working" error
body: <p>I have used Keras remotely, such as on Colab and AWS. Today, I tried to install Keras on my laptop using pip3 install keras, and the message was that keras was already installed on the computer (I must have installed it before):</p>
  <pre><code>WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
  Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
  To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
  Requirement already satisfied: keras in /usr/local/lib/python3.7/site-packages/Keras-2.4.3-py3.7.egg (2.4.3)
  Requirement already satisfied: h5py in /usr/local/lib/python3.7/site-packages/h5py-2.10.0-py3.7-macosx-10.15-x86_64.egg (from keras) (2.10.0)
  Requirement already satisfied: numpy&gt;=1.9.1 in /usr/local/lib/python3.7/site-packages (from keras) (1.16.4)
  Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/site-packages/PyYAML-5.3.1-py3.7-macosx-10.15-x86_64.egg (from keras) (5.3.1)
  Requirement already satisfied: scipy&gt;=0.14 in /usr/local/lib/python3.7/site-packages (from keras) (1.2.0)
  Requirement already satisfied: six in /usr/local/lib/python3.7/site-packages (from h5py-&gt;keras) (1.12.0)
  </code></pre>
  <p>However, when I tried to <code>import keras</code>, I received this message:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py&quot;, line 3267, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File &quot;&lt;ipython-input-21-88d96843a926&gt;&quot;, line 1, in &lt;module&gt;
      import keras
  ModuleNotFoundError: No module named 'keras'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py&quot;, line 2018, in showtraceback
      stb = value._render_traceback_()
  AttributeError: 'ModuleNotFoundError' object has no attribute '_render_traceback_'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/IPython/core/ultratb.py&quot;, line 1095, in get_records
      return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
    File &quot;/usr/local/lib/python3.7/site-packages/IPython/core/ultratb.py&quot;, line 313, in wrapped
      return f(*args, **kwargs)
    File &quot;/usr/local/lib/python3.7/site-packages/IPython/core/ultratb.py&quot;, line 347, in _fixed_getinnerframes
      records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py&quot;, line 1502, in getinnerframes
      frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py&quot;, line 1460, in getframeinfo
      filename = getsourcefile(frame) or getfile(frame)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py&quot;, line 696, in getsourcefile
      if getattr(getmodule(object, filename), '__loader__', None) is not None:
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py&quot;, line 733, in getmodule
      if ismodule(module) and hasattr(module, '__file__'):
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/__init__.py&quot;, line 50, in __getattr__
      module = self._load()
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/__init__.py&quot;, line 44, in _load
      module = _importlib.import_module(self.__name__)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py&quot;, line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1006, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 953, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1006, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 983, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 967, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 677, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 728, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/__init__.py&quot;, line 32, in &lt;module&gt;
      from tensorflow._api.v1 import app
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/_api/v1/app/__init__.py&quot;, line 10, in &lt;module&gt;
      from tensorflow.python.platform.app import run
    File &quot;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py&quot;, line 23, in &lt;module&gt;
      from absl.app import run as _run
  ModuleNotFoundError: No module named 'absl'
  </code></pre>
  <p>I Googled to find similar problems and I found some suggestions to try <code>sudo pip3 install keras</code>. Keras was downloaded again. However, when I typed <code>import keras</code>, it still produced errors.</p>
  <p>Also, I read this Stack Overflow question: <a href="https://stackoverflow.com/questions/57156410/how-to-fix-import-keras-error-with-python-console">How to fix import keras error with python console</a>, but the solution does not work for me as I am calling a library which calls <code>import keras</code>, so I need the <code>import keras</code> command to work (I can't make it call <code>import tensorflow.keras</code>).</p>
  <p>Why is this error happening?</p>
  <p>Note: I am using Python 3.7.5. I checked the version of pip through <code>pip --version</code>, getting this message:</p>
  <pre><code>WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
  Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
  To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
  pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
  </code></pre>
  <p>Also, I am running this code in Jupyter Notebook. I have checked that Python 3.7 is being run by Jupyter Notebook.</p>