ImportError: cannot import name ‘context’

this is my final task on college and i’m new to python… my coding is about emotion recognition with fer library. i had installed all of required library. this is my code

import os
import sys

import matplotlib
if == 'posix' and "DISPLAY" not in os.environ:

import matplotlib.pyplot as plt

from fer.fer import FER
from fer import Video
import cv2

if _name_ == "_main_":
        videofile = sys.argv[1]
        videofile = "test.mp4"
    detector = FER(mtcnn=True)
    video = Video(videofile)

    # Output list of dictionaries
    raw_data = video.analyze(detector, display=False)

    # Convert to pandas for analysis
    df = video.to_pandas(raw_data)
    df = video.get_first_face(df)
    df = video.get_emotions(df)

    # Plot emotions

and i got this error :

Using TensorFlow backend.
Traceback (most recent call last):
  File "", line 12, in <module>
    from fer.fer import FER
  File "/home/jn-a02/.local/lib/python3.6/site-packages/fer/", line 38, in <module>
    from keras.models import load_model
  File "/home/jn-a02/.local/lib/python3.6/site-packages/keras/", line 3, in <module>
    from . import utils
  File "/home/jn-a02/.local/lib/python3.6/site-packages/keras/utils/", line 6, in <module>
    from . import conv_utils
  File "/home/jn-a02/.local/lib/python3.6/site-packages/keras/utils/", line 9, in <module>
    from .. import backend as K
  File "/home/jn-a02/.local/lib/python3.6/site-packages/keras/backend/", line 1, in <module>
    from .load_backend import epsilon
  File "/home/jn-a02/.local/lib/python3.6/site-packages/keras/backend/", line 90, in <module>
    from .tensorflow_backend import *
  File "/home/jn-a02/.local/lib/python3.6/site-packages/keras/backend/", line 6, in <module>
    from tensorflow.python.eager import context
ImportError: cannot import name 'context'

I’m using Nvidia Jetson Nano A02, I’m pretty new to programming so I don’t know about this error. Can any one recommend what can I do to resolve it? Thanks


This error is related to the TensorFlow version you installed.
Just check the version v2.4 and v1.15.x, both have tensorflow.python.eager.context:

Could you check which TensorFlow version you are used first?

$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2021-06-28 11:48:01.185781: I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library
>>> tf.__version__


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.