Skip to content Skip to sidebar Skip to footer

ImportError: Cannot Import Name 'context' From 'tensorflow.python.eager' (unknown Location)

I created virtual environment and installed both tensorflow and tensorflow-gpu. After that I installed keras. And then I checked in my conda terminal by importing keras and I was a

Solution 1:

Did you installed the dependencies with conda? Like this:

 $ conda install -c conda-forge keras

 $ conda install -c conda-forge tensorflow

 $ conda install -c anaconda tensorflow-gpu

If you installed with pip they will not work inside your virtual env. Look at your conda dependencies list, to see if the tensorflow and keras are really there using:

$ conda list

If they are, activate your virtual environment:

$ conda activate 'name_of_your_env'

And run the jupyter inside that, should be something like that (if your env shows in parenthesis the activation worked, and you are now inside the virtual env):

(your_env)$ jupyter notebook

Solution 2:

Doing below solved my issue.

So I removed all the packages that were installed via pip and intstalled packages through conda. I had environment issue and created another environment from the scratch and ran below commands. Create virtual environment:

conda create -n <env_name>

Install tensorflow-gpu via conda and not pip. If you skip create environment command, type in below as it will scratch off new env and specify python and tensorflow version.

conda create -n <env_name> python=3.6 tensorflow-gpu=2.2

And then I had to make sure that jupyter notebook is opening with the environment that I want it to open with. For that below code.

C:\Users\Adi(Your user here)\Anaconda3\envs\env_name\python.exe -m ipykernel install --user --name <env_name> --display-name "Python (env_name)"

When you go to Jupyter notebook, on the top right corner you should see your virtual environment and make sure you select that. And it got resolved like that.


Post a Comment for "ImportError: Cannot Import Name 'context' From 'tensorflow.python.eager' (unknown Location)"