I’m trying to use VS Code to start a small data science project, I’m currently having issues while importing keras
by running the following lines:
LSTM and GRU project
Dependencies
<code>import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import LSTM, Dropout, Dense
<code>import pandas as pd
import matplotlib as mpl
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import LSTM, Dropout, Dense
</code>
import pandas as pd
import matplotlib as mpl
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import LSTM, Dropout, Dense
Traceback goes as follow:
ImportError Traceback (most recent call
last) ~AppDataLocalTempipykernel_21244449270897.py in <cell line:
6>()
4 import matplotlib as mpl
5 from sklearn.preprocessing import MinMaxScaler
—-> 6 from keras.models import Sequential
7 from keras.layers import LSTM, Dropout, Dense
c:UsersResetStoreXAppDataLocalProgramsPythonPython39libsite-packageskeras_init_.py
in
8
9 # Import everything from /api/ into keras.
—> 10 from keras.api import * # noqa: F403
11 from keras.api import version # Import * ignores names start with “_”.
12
c:UsersResetStoreXAppDataLocalProgramsPythonPython39libsite-packageskerasapi_init_.py
in
6
7
—-> 8 from keras.api import activations
9 from keras.api import applications
10 from keras.api import backend
c:UsersResetStoreXAppDataLocalProgramsPythonPython39libsite-packageskerasapiactivations_init_.py
in
5 “””
6 …
—> 10 raise ImportError(
11 “To use Keras, you need to have optree
installed. ”
12 “Install it via pip install optree
“
ImportError: To use Keras, you need to have optree
installed.
Install it via pip install optree
Output is truncated. View as a
scrollable element or open in a text editor. Adjust cell output
settings…
I decided to run in the terminal commands like pip install keras --upgrade --user
to check if any of the dependencies above are indeed not installed, the output is quite disappointing since it states that every single dependency used in this project has its requirements already satisfied, see:
<code>C:UsersResetStoreXDownloadsCryptobote 2024> pip install numpy --upgrade --user
Requirement already satisfied: numpy in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (1.26.4)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install optree --upgrade --user
Requirement already satisfied: optree in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (0.11.0)
Requirement already satisfied: typing-extensions>=4.0.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from optree) (4.2.0)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install keras --upgrade --user
Requirement already satisfied: keras in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (3.3.3)
Requirement already satisfied: numpy in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (1.26.4)
Requirement already satisfied: optree in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (0.11.0)
Requirement already satisfied: h5py in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (3.11.0)
Requirement already satisfied: ml-dtypes in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (0.4.0)
Requirement already satisfied: absl-py in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (2.1.0)
Requirement already satisfied: rich in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (13.3.1)
Requirement already satisfied: typing-extensions>=4.0.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from optree->keras) (4.2.0)
Requirement already satisfied: pygments<3.0.0,>=2.14.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from rich->keras) (2.14.0)
Requirement already satisfied: mdurl~=0.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from markdown-it-py<3.0.0,>=2.1.0->rich->keras) (0.1.2)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install pandas --upgrade --user
Requirement already satisfied: pandas in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (2.2.2)
Requirement already satisfied: python-dateutil>=2.8.2 in c:usersresetstorexappdataroamingpythonpython39site-packages (from pandas) (2.8.2)
Requirement already satisfied: tzdata>=2022.7 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from pandas) (2024.1)
Requirement already satisfied: pytz>=2020.1 in c:usersresetstorexappdataroamingpythonpython39site-packages (from pandas) (2021.3)
Requirement already satisfied: numpy>=1.22.4 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from pandas) (1.26.4)
Requirement already satisfied: six>=1.5 in c:usersresetstorexappdataroamingpythonpython39site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install matplotlib --upgrade --user
Requirement already satisfied: matplotlib in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (3.8.4)
Requirement already satisfied: packaging>=20.0 in c:usersresetstorexappdataroamingpythonpython39site-packages (from matplotlib) (24.0)
Requirement already satisfied: importlib-resources>=3.2.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (6.4.0)
Requirement already satisfied: numpy>=1.21 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.26.4)
Requirement already satisfied: fonttools>=4.22.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (4.33.3)
Requirement already satisfied: kiwisolver>=1.3.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.4.2)
Requirement already satisfied: pillow>=8 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (8.4.0)
Requirement already satisfied: cycler>=0.10 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (0.11.0)
Requirement already satisfied: python-dateutil>=2.7 in c:usersresetstorexappdataroamingpythonpython39site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: contourpy>=1.0.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.2.1)
Requirement already satisfied: pyparsing>=2.3.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (3.0.9)
Requirement already satisfied: zipp>=3.1.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from importlib-resources>=3.2.0->matplotlib) (3.6.0)
Requirement already satisfied: six>=1.5 in c:usersresetstorexappdataroamingpythonpython39site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)
WARNING: There was an error checking the latest version of pip.
<code>C:UsersResetStoreXDownloadsCryptobote 2024> pip install numpy --upgrade --user
Requirement already satisfied: numpy in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (1.26.4)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install optree --upgrade --user
Requirement already satisfied: optree in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (0.11.0)
Requirement already satisfied: typing-extensions>=4.0.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from optree) (4.2.0)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install keras --upgrade --user
Requirement already satisfied: keras in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (3.3.3)
Requirement already satisfied: numpy in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (1.26.4)
Requirement already satisfied: optree in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (0.11.0)
Requirement already satisfied: h5py in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (3.11.0)
Requirement already satisfied: ml-dtypes in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (0.4.0)
Requirement already satisfied: absl-py in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (2.1.0)
Requirement already satisfied: rich in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (13.3.1)
Requirement already satisfied: typing-extensions>=4.0.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from optree->keras) (4.2.0)
Requirement already satisfied: pygments<3.0.0,>=2.14.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from rich->keras) (2.14.0)
Requirement already satisfied: mdurl~=0.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from markdown-it-py<3.0.0,>=2.1.0->rich->keras) (0.1.2)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install pandas --upgrade --user
Requirement already satisfied: pandas in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (2.2.2)
Requirement already satisfied: python-dateutil>=2.8.2 in c:usersresetstorexappdataroamingpythonpython39site-packages (from pandas) (2.8.2)
Requirement already satisfied: tzdata>=2022.7 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from pandas) (2024.1)
Requirement already satisfied: pytz>=2020.1 in c:usersresetstorexappdataroamingpythonpython39site-packages (from pandas) (2021.3)
Requirement already satisfied: numpy>=1.22.4 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from pandas) (1.26.4)
Requirement already satisfied: six>=1.5 in c:usersresetstorexappdataroamingpythonpython39site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install matplotlib --upgrade --user
Requirement already satisfied: matplotlib in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (3.8.4)
Requirement already satisfied: packaging>=20.0 in c:usersresetstorexappdataroamingpythonpython39site-packages (from matplotlib) (24.0)
Requirement already satisfied: importlib-resources>=3.2.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (6.4.0)
Requirement already satisfied: numpy>=1.21 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.26.4)
Requirement already satisfied: fonttools>=4.22.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (4.33.3)
Requirement already satisfied: kiwisolver>=1.3.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.4.2)
Requirement already satisfied: pillow>=8 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (8.4.0)
Requirement already satisfied: cycler>=0.10 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (0.11.0)
Requirement already satisfied: python-dateutil>=2.7 in c:usersresetstorexappdataroamingpythonpython39site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: contourpy>=1.0.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.2.1)
Requirement already satisfied: pyparsing>=2.3.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (3.0.9)
Requirement already satisfied: zipp>=3.1.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from importlib-resources>=3.2.0->matplotlib) (3.6.0)
Requirement already satisfied: six>=1.5 in c:usersresetstorexappdataroamingpythonpython39site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)
WARNING: There was an error checking the latest version of pip.
</code>
C:UsersResetStoreXDownloadsCryptobote 2024> pip install numpy --upgrade --user
Requirement already satisfied: numpy in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (1.26.4)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install optree --upgrade --user
Requirement already satisfied: optree in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (0.11.0)
Requirement already satisfied: typing-extensions>=4.0.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from optree) (4.2.0)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install keras --upgrade --user
Requirement already satisfied: keras in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (3.3.3)
Requirement already satisfied: numpy in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (1.26.4)
Requirement already satisfied: optree in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (0.11.0)
Requirement already satisfied: h5py in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (3.11.0)
Requirement already satisfied: ml-dtypes in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (0.4.0)
Requirement already satisfied: absl-py in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (2.1.0)
Requirement already satisfied: rich in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from keras) (13.3.1)
Requirement already satisfied: typing-extensions>=4.0.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from optree->keras) (4.2.0)
Requirement already satisfied: pygments<3.0.0,>=2.14.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from rich->keras) (2.14.0)
Requirement already satisfied: mdurl~=0.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from markdown-it-py<3.0.0,>=2.1.0->rich->keras) (0.1.2)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install pandas --upgrade --user
Requirement already satisfied: pandas in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (2.2.2)
Requirement already satisfied: python-dateutil>=2.8.2 in c:usersresetstorexappdataroamingpythonpython39site-packages (from pandas) (2.8.2)
Requirement already satisfied: tzdata>=2022.7 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from pandas) (2024.1)
Requirement already satisfied: pytz>=2020.1 in c:usersresetstorexappdataroamingpythonpython39site-packages (from pandas) (2021.3)
Requirement already satisfied: numpy>=1.22.4 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from pandas) (1.26.4)
Requirement already satisfied: six>=1.5 in c:usersresetstorexappdataroamingpythonpython39site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
WARNING: There was an error checking the latest version of pip.
C:UsersResetStoreXDownloadsCryptobote 2024> pip install matplotlib --upgrade --user
Requirement already satisfied: matplotlib in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (3.8.4)
Requirement already satisfied: packaging>=20.0 in c:usersresetstorexappdataroamingpythonpython39site-packages (from matplotlib) (24.0)
Requirement already satisfied: importlib-resources>=3.2.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (6.4.0)
Requirement already satisfied: numpy>=1.21 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.26.4)
Requirement already satisfied: fonttools>=4.22.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (4.33.3)
Requirement already satisfied: kiwisolver>=1.3.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.4.2)
Requirement already satisfied: pillow>=8 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (8.4.0)
Requirement already satisfied: cycler>=0.10 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (0.11.0)
Requirement already satisfied: python-dateutil>=2.7 in c:usersresetstorexappdataroamingpythonpython39site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: contourpy>=1.0.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (1.2.1)
Requirement already satisfied: pyparsing>=2.3.1 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from matplotlib) (3.0.9)
Requirement already satisfied: zipp>=3.1.0 in c:usersresetstorexappdatalocalprogramspythonpython39libsite-packages (from importlib-resources>=3.2.0->matplotlib) (3.6.0)
Requirement already satisfied: six>=1.5 in c:usersresetstorexappdataroamingpythonpython39site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)
WARNING: There was an error checking the latest version of pip.
My Python Interpreter is Python 3.9.6 64-bit
, and I am sure all of the dependencies above were installed in its corresponding path, I tried to uninstall and reinstall keras
and optree
including running pip cache purge
as well as rebooting the kernel, but it still throws the same error.
I also noticed that keras.models
and keras.layers
are underlined, and when I “hover over them” it displays
Import “keras.models” could not be resolved Pylance(reportMissingImports)
So, I’m stuck, I would like to realize what to do to handle this?