ModuleNotFoundError: No module named 'tensorflow' on Jupyter Notebook - python

when I try to import keras on a Jupyter notebook I receive this error message: ModuleNotFoundError: No module named 'tensorflow'.
I need to use keras to build an LSTM model fora project and am a beginner in python so I don't know how to get around this error. I have tried to install tenserflow and keras into an environment on anaconda but I receive the same error. For reference, I am using a Mac.
My code:
#Import libraries used
import math
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import numpy as np
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense, LSTM
Any help would be greatly appreciated!

Related

ImportError: cannot import name 'keras' from 'tensorflow'

I'm try learning TensorFlow but i have a problem. I'm importing TensorFlow like in official website but i take a error.
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
Traceback (most recent call last):
File "C:\Users\Koray\Desktop\Python\main.py", line 4, in
from tensorflow import keras
ImportError: cannot import name 'keras' from 'tensorflow'
(C:\Users\Koray\Desktop\Python\tensorflow.py)
For community benefit, adding #John Gordon answer here in the answer section.
Don't name your script tensorflow.py. Your import finds that script instead of the real one.
Instead you can name any other for example learning.py. Now all your imports work as expected.
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

Importing Adam and ImageDataGenerator on google colab failed

I'm implementing a UNet neural network but I'm having some issues while importing libraries. I found a solution for a couple of them, but I still have a problem with these two imports:
from tensorflow.keras.optimizers import Adam
#Import "tensorflow.keras.optimizers" could not be resolved(reportMissingImports)
from tensorflow.keras.preprocessing.image import ImageDataGenerator
#Import "tensorflow.keras.preprocessing.image" could not be resolved(reportMissingImports)
I've already imported:
import tensorflow as tf
from tensorflow import keras
from keras import layers
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
import numpy as np
Any idea? I've tried to change but it still raises an error.

Problem with dependencies in Streamlit app

When I try to run my streamlit app I get these errors in Anaconda Prompt:
I simplified the code to be more readable, but basically it process an input with a Keras model, then I save this model with pickle in order to make predictions afterwards with Streamlit API
import streamlit as st
import cv2 as cv
import matplotlib.pyplot as plt
import pandas as pd
import os
import numpy as np
import keras
from keras.models import Sequential
import joblib
import pickle
def some_function():
pass #some function to preprocess data and train a model with Keras
def main():
ruta_to_model=r'path'
model = pickle.load(open(os.path.join(ruta_to_model,'model_pose.pkl'),'rb'))
st.set_page_config(page_title='Pose Framework',layout='wide',initial_sidebar_state='expanded')
files=[]
for file in os.listdir(r'path'):
if file.endswith('.jpg'):
files.append(file)
option=st.multiselect('Input:', files)
if option and st.button('Predict'):
inputs=some_function()
model.predict(inputs)
The error contains
ImportError: cannot import name 'DataFrame' from 'pandas' (unknown location)
Have you installed pandas inside your conda environment?
conda install pandas

I m getting error 'unresolved import keras.layers.experimental' in visual studio

I m getting error 'unresolved import keras.layers.experimental' in visual studio
my python import list is like this
import sys
import math
import pandas_datareader as web
import numpy as np
import pandas.testing as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
i think problem is becouse windows cant using these libs but im not sure

module 'pandas' has no attribute 'DataFrame' when using alibi package in Python

I'm hoping someone can help me. When I run the following setup I get the error below. It seems like the alibi package is causing it. The other posts related to this problem are either because of case sensitive spellings of 'DataFrame' or .py filenames.
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR) # suppress deprecation messages
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.models import Model, load_model
from tensorflow.keras.utils import to_categorical
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
from sklearn.datasets import load_boston
from alibi.explainers import CounterFactualProto
AttributeError: module 'pandas' has no attribute 'DataFrame'

Categories

Resources