Python Forum
Error in code tensorflow is installed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in code tensorflow is installed
#1
The following code on Windows 10 creates the error shown.


import math
import numpy as np
import pandas as pd
import os
import yfinance as yf
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
%matplotlib inline
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

from keras.models import Sequential
from keras import layers
from keras.layers import Activation, Dropout, Flatten, Dense, Conv2D, MaxPooling2D
Error:
ModuleNotFoundError Traceback (most recent call last) ~\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\__init__.py in <module> 2 try: ----> 3 from tensorflow.keras.layers.experimental.preprocessing import RandomRotation 4 except ImportError: ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental' During handling of the above exception, another exception occurred: ImportError Traceback (most recent call last) <ipython-input-1-162fe132a741> in <module> 10 register_matplotlib_converters() 11 ---> 12 from keras.models import Sequential 13 from keras import layers 14 from keras.layers import Activation, Dropout, Flatten, Dense, Conv2D, MaxPooling2D ~\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\__init__.py in <module> 4 except ImportError: 5 raise ImportError( ----> 6 'Keras requires TensorFlow 2.2 or higher. ' 7 'Install TensorFlow via `pip install tensorflow`') 8 ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
However, tensorflow is installed. Both pip list and conda list confirm this.So what is going on? I am using tensorflow 2.3.

Any help appreciated.Thanks in advance.

Respectfuuly,

ErnestTBass
Reply
#2
perhaps you have more that one version of python?
each version has it's own copy.

to find current version of pip and python:
from command line:
python -V
pip -V

to see what's installed: pip list

You can use pyenv which will allow switching from one version to another very simply
see: https://python-forum.io/Thread-pyenv-Sim...Management
Reply
#3
The error is caused by a line you have not included, within that try except block.
Add this
import tensorflow as tf
tf.__version__
and report result please.
J
Reply
#4
You have a lot of this Threads about installing a lot of different stuff @ErnestTBass.
I have answers in many of your Threads,but many times you don't answer back,and just start a new Thread.
Take this Thread as example where i show how to install whole R stack in Anaconda.

With all the explanation i and others have done in many of your Threads,i am not sure how much of this you take in and understand.
If don't understand the basic of this will have same problem again and again.

Is this Thread about the same as you started in previous Thread ?
Then that info should be here,or you should not have started a new Thread.
Reply
#5
I installed tensorflow and keras on my Windows 10 Pro system months ago. I was a little surprised because I know that I used my keras environment before. When I read the initial error it said I must use tensorflow 2.2, I had 2.1. I upgraded and it still says I need to install tensorflow 2.2.

I could not understand the error because as I said conda list and said that I had tensorflow 2.2 installed. So why the error?

This is not related except we are again talking about tensorflow and here it says that it is not installed. I can show you the output of conda list and pip list that claims that tensorflow 2.2 is installed.

I usually run a Docker image/containers when doing this with Ubuntu, but recently started using jupyter notebook on Windows 10.

I have never had an easy time of it using jupyter notebook on Windows 19, but things were going well until yesterday afternoon.

I upgraded both tensorflow and keras to the highest level, I could. Whenever, I did the installer found the previous version,
removed it and installed a later version either keras or tensorflow..

If the installer can find tensorflow, why can't the interpreter?

I will bet even money that this will go very well on a Docker containers. Why does it screw up with Windows 10 native? I do not know.

As I said, keras and tensorflow are there!!!, and are the latest versions. Why can't jupyter notebook for Windows 10 find them while the upgrade software has no trouble.I thought this was a forum, I did not know it exists to berate people who ask intelligent questions. It sure seems that is your mission statement.

I just cannot understand why the python interpreter cannot find the latest and greatest tensorflow that is installed.

I do not understand several things about python. The first is this for this question.

I also installed yfinance and I used pip to do it, because conda would not. If I run pip list and conda list then, only pip list shows yfinance.

Why do pip list and conda sometimes give different outputs? They give the same on tensorflow and keras, however.

There Are other things to bring up, but this post is already too long.

I ask questions is good faith. In my past I answered similar question, Fortran, c, Pascal at help desk. I never thought the jobor questions were beneath me.

Respectfully,

ErnestTBass
Reply
#6
Again you mix a lot stuff into this Doh
AppData\Local\Programs\Python\Python37
Let's make one thing be clear when you have this path to Python,you are not using Anaconda/conda or virtual environment.
So do not mention conda or Docker,as it has nothing do about what you using now.
Now use Python 3.7 for python.org,it has no connection to Anaconda/conda that is a standalone version.

I would not install all of to this on a root original Python version(as you do now),
i could show how this is done in a virtual environment with venv.
virtual environment is used to avoid version problems as you have now,as all most be installed new into environment.

Anacondas could be used,but as mention has nothing to with what use use now,as it's stand alone
Anaconda has both conda and pip(tied to only Anaconda and not python.org version).

A little frustrating as i have show this before in our Threads,
but you still seems to mix stuff together and do not understand basic concept of this.

An other way here i use CoLab Notebook,just to pip install yfinance ,
then all you import's work,and you don't have to any installation of Keras/Tensorflow as that's already done.
Larz60+ likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error : "Microsoft Visual C++ 14.0 is required. " Even its installed Barak 4 2,478 Oct-13-2021, 10:39 PM
Last Post: Underscore
  Installed pip install openpyxl, Requirement already satisfied, but, still have error jonah88888 3 3,408 Sep-24-2021, 02:11 AM
Last Post: jonah88888
  ibm_db error even though package is installed runnerpaul 6 7,460 Mar-28-2017, 07:22 AM
Last Post: runnerpaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020