Problem with dependencies in Streamlit app - python

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

Related

ERROR: "ImportError: DLL load failed while importing defs: Unable to find the specifiedprocedure" using Keras in touchDesigner

This is my first post in Stack OverFlow so I hope to be clear enough.
I'm trying to use a keras model in touchDesigner loading h5 file format with the function " keras.models.load_model("my_model.h5") ". I'm using Windows 10. If i run the file in VSCode, for example, the file works but if i try to run it in touchDesigner i obtain this : ERROR:"ImportError: DLL load failed while importing defs: Unable to find the specifiedprocedure". I have already tryed to unistall and re-install h5py but not working.
Any ideas?
My Code:
import sys
mypath= "C:\users\MyUser\appdata\local\programs\python\python310\lib\site-packages"
if mypath not in sys.path:
sys.path.append(mypath) print("in")
import tensorflow as tf
from tensorflow import keras
from keras.models import load_model
print(tf.version.VERSION)
import numpy as np import os
import h5py # HERE I OBTAIN THE ERROR
pathToMOdel = "C:\Users\MyUser\Desktop\corsoTouchDesigner\Modelli\generatoreAstratto.h5" print(pathToMOdel)
def onStart():
new_model = load_model(pathToMOdel)
print(new_model)
return
onStart()

ModuleNotFoundError: No module named 'tensorflow' on Jupyter Notebook

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!

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'

Cannot set up tensorflow gpu object detection

I tried to follow a tutorial on how to setup tensorflow gpu (https://www.youtube.com/watch?v=tPq6NIboLSc) but on the jupyter step i am getting this error :https://pastebin.com/gm3g8cC5
(ive set in in a pastebin because its very long)
I dont know what to do, ive also tried others tutorial but none of the others works, they also got errors ( but they are differents) at the jupyter step.
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.12.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.')
Here is the part where the errors pops.
I dont know what is my tensorflow version since when i am trying to import it i am getting OSError: [WinError 193] %1 is not a valid Win32 application

Why does %config line give me syntax error in Python 3.7?

I am creating a system in order to predict earthquakes. There's this code in which there is a line %config InlineBackend.figure_format = 'retina'.
Whenever I run my python code it gives the error as ("% invalid syntax").
Earlier I had the problem of %matplotlib statement which I figured out through google. But, this problem is sucking me.
https://www.kaggle.com/pablocastilla/predict-earthquakes-with-lstm ("The source from where the code has been taken")
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from subprocess import check_output
from keras.layers.core import Dense, Activation, Dropout
from keras.layers.recurrent import LSTM
from keras.models import Sequential
from sklearn.cross_validation import train_test_split
import time #helper libraries
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from numpy import newaxis
from geopy.geocoders import Nominatim
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
import warnings
warnings.filterwarnings('ignore')
%config InlineBackend.figure_format = 'retina'
# Any results you write to the current directory are saved as output.
from subprocess import check_output
print(check_output(["ls", "../input"]).decode("utf8"))
So it is showing "error invalid syntax " and the % sign before the word config has been highlighted.
The expected output is that I should not recieve an error and any results that are written to the directory are given out.
That % syntax is defining a IPython Magic Command. Read: Magic commands
Give this a try
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')
Taken from Configure the backend of Ipython to use retina display mode with code
You need to install Ipython library in order to do this. Also if you get "No module named ipykernel" then install ipykernel.
pip install ipython
pip install ipykernel
Edit: but I highly recommend using jupyter notebooks for example give google colab a try : https://colab.research.google.com/notebooks/welcome.ipynb
Commands starting with % are not valid python commands, they are only supported by ipython/jupyter interpreter, not by the official python interpreter.

Categories

Resources