Tell us what’s happening:
The pre-set library imports are giving me an error.
Your code so far
import libraries
try:
%tensorflow_version only exists in Colab.
!pip uninstall -y tensorflow tensorflow-datasets ml-dtypes
!pip install tf-nightly tensorflow-datasets
except Exception:
pass
import tensorflow as tf
import pandas as pd
import keras # Import keras as a top-level package
import numpy as np
import matplotlib.pyplot as plt
print(tf.version)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Machine Learning with Python Projects - Neural Network SMS Text Classifier
1 Like
If you’re using Google colab, Tensorflow libraries are already installed, so there’s no need to change them. If you’re installing any new libraries then use !pip install library_name at the top of your notebook. and a try-catch block is not always necessary. Good Luck!
# Add as the first cell
!pip uninstall -y tf-nightly keras-nightly protobuf
!pip install tensorflow==2.20.0 # Version doesn't matter much here, the default one will work as well - 2.19.0
# Remove this
try:
# %tensorflow_version only exists in Colab.
!pip install tf-nightly
except Exception:
pass
First, start a new collab - terminate any sessions in runtime → manage sessions if there are any - then add a new first cell with the code to add above starting with - !pip install - and run it - when it asks for a restart of the session, do it - press a button at the bottom of the output of the cell. Remove the code starting with - try: #… - from the second cell and run it, you don’t have to run the first cell again.
This fixed it for me