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

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?

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.

Related

How to solve ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`?

I get this error when I try to import Keras into my project.
How to solve ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow
I verified the versions I have installed (with pip) for everything and I have:
Python 3.7.7
Tensorflow 2.2.0
keras 2.4.3
I have linked a picture of the full error. There is some stuff about Dll but I'm not sure if this is what creates the error.
Tensorflow requires Python 3.5–3.8 , pip and venv >= 19.0
in order to fix it:
sudo apt install python3-pip
pip3 install --upgrade pip
python3 -m pip install tensorflow
if you already had tensorflow installed substitute the last command this this:
pip3 install --upgrade tensorflow
hope it helped.
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow
Fix:
python -m pip install –upgrade pip
pip install keras==2.1.5
This worked for me.
If above step are not solving the error then check your libraries with specific version.
Python==3.6.4
Numpy==1.18.5
Pandas==1.1.4
scikit-learn==0.21.2
Tensorflow==1.13.1
keras==2.1.5
Hope this worked for you.
Please update keras version.
python -m pip install –upgrade pip

No Module Named Tensorflow - Anaconda

I'm pretty new to Tensorflow. I've installed the package using
conda install -c conda-forge tensorflow
When I import tensorflow now, I get the No Module named Tensorflow error. I've been searching for a way out and have failed. It wold mean a lot if someone could help me with this. Thanks
run following commands:
conda create -n tensorflow
activate tensorflow
conda install -c conda-forge tensorflow
else you can install it with pip command:
pip install tensorflow

TensorFlow 1.9.0 and Python 3.6.5

I'm trying to upgrade to Tensorflow 1.9 within a conda environment (Ubuntu 16.04). I am using python 3.6.5. When I try this:
source activate myenv
sudo -H pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0rc0-cp36-cp36m-linux_x86_64.whl
I get the error:
tensorflow-1.9.0rc0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform.
Seems strange because the same thing worked fine for TF 1.8
TensorFlow seems to install fine without sudo -H but then when I try:
python -c "import tensorflow as tf; print(tf.__version__)"
I get the following error:
from tensorflow.python.keras._impl.keras.backend import abs
ImportError: cannot import name 'abs'
I can't install from conda because it still has 1.8 when I check with:
conda install -c conda-forge tensorflow
With sudo you're installing locally. So, remove sudo -H to install over your Environment.
also, you need the python developer library locally:
Ubuntu: apt-get install python3-dev
RHEL/Fedora: dnf install python3-devel
Mac OS: check your environment variables or try re-installing?
Windows: check your environment variables or try re-installing?
Sometimes because of outdated pip also this can happen . Try this inside that environment and let me know
python -m pip install --upgrade pip
Try to check if conda has 1.9
conda install -c conda-forge tensorflow
I figured out that this Tensorflow is a pre-release not the complete release, as a result you can upgrade it using pip directly.
You can remove your installed release and try to install this else wait for couple of weeks after that you can directly update via conda forge or pip.

Cannot run keras

I want to run keras on anaconda for convolution neural network using mnist handwriting recognition. A day before everything worked fine but as I try to run the same program, i get the following error in the first line:
from keras.datasets import mnist (first line of code)
ModuleNotFoundError: No module named 'keras.datasets'; 'keras' is not
a package
I also created virtual environment to use python 3.5 as my python version is 3.6. I have installed both keras and tensorflow. How do i fix the above error? Perhaps it is related to path and not error with keras. My anaconda is installed in E: whearas working environment is C:\Users\Prashant Mahato.
Do you get an error message if you just import keras? I was getting a similar error in the command line and then implemented in Spyder (using Anaconda) and it worked fine.
Here is how I install Keras and other related dependencies
conda create -n <Environment_Name> python=3.6
activate <Environment_Name>
conda update --all
conda install mingw libpython
conda install scipy
conda install numpy
conda install mkl
conda install -c conda-forge tensorflow
conda install theano
pip install pyyaml
pip install h5py
pip install keras
conda install -c conda-forge tmux
conda install pandas
condas install pillow
conda install scikit-learn
conda install -c menpo opencv3
To check if everything is work as it should just import all the packages in python within the environment created.
I'm running Windows 10 and Anaconda 4.2
If running Ubuntu, replace
activate <Environment_Name>
with
source activate <Environment_Name>
HTH.

install Tensorflow 1.0 on windows by Anaconda error

By following the instructions on Tensorflow website, I tried to install cpu-only version Tensorflow by Anaconda. However, the 4th step
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.0-cp35-cp35m-win_x86_64.whl
outputs an error:
tensorflow-1.0.0-cp35-cp35m-win_x86_64.whl is not a supported wheel on this platform. Could anyone tell me the reason behind this?
The command on the website is currently wrong. Replace x86_64 at the end of the URL with amd64 to get the correct command:
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.0-cp35-cp35m-win_amd64.whl
Alternatively you can use the following simpler command to install the latest CPU version:
pip install --ignore-installed --upgrade tensorflow
I think your problems could be one of this:
your python version is not Python3.5
Your system is not x64 windows.
So you can change install method below.
You can install tensorflow with pip direct like this:
pip install tensorflow
but this works only pip version > 9,
if you're using pip version under 9, you have to upgrade pip first.
you can upgrade your pip with this:
pip install -U pip
if you've installed python for all user, you might run this code with administrator account.

Categories

Resources