Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: "No module named tensorflow" (Keras in Anaconda environment)

Tags:

I have installed Keras and tensorflow using pip in Anaconda environment, but when I run Keras program in tensorflow background it gives error No module named tensorflow. Can you please help?

like image 451
Abhishek Avatar asked Jun 07 '17 09:06

Abhishek


People also ask

How do I fix No module named in TensorFlow?

The Python "ModuleNotFoundError: No module named 'tensorflow'" occurs when we forget to install the tensorflow module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install tensorflow command.

How do I fix No module named keras?

We can fix no module named Keras using installing and reinstalling keras. We can install the Keras module using pip, conda, source code, etc.


1 Answers

Check your python version and installation command. ($ conda create -n tensorflow python=<version>)

If you install tensorflow via conda-forge use:

# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
(tensorflow)$ conda install -c conda-forge tensorflow

Otherwise, switch the pip command according to the python version like:

# Python 2
(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL

# Python 3
(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL

If this doesn't solve your problem, please provide more detailed command lines to reproduce the problem.

like image 99
Satoshi Kataoka Avatar answered Sep 30 '22 00:09

Satoshi Kataoka