optree is actually installed but when running “from keras.models import Sequential” it still throws ImportError asking me to install optree, why?

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật