W2 Lab doesnt work - Cannot import dependencies

Before you post, please make sure to:

  1. Add a clear title W2 Lab doesnt work - Cannot import dependencies

  2. Add all required tags in the tag option (top-right of the post):

    • Coursera Platform

    • generative-ai-with-llms/week 2 lab

  3. Write a detailed description Cells 2 and 3 of the lab do not work, due to which right libraries and dependencies aren’t loaded.

**Screenshot and log below :

  1. Cell Below**


WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
Requirement already satisfied: pip in /opt/conda/lib/python3.12/site-packages (26.0.1)
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
Note: you may need to restart the kernel to use updated packages.
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
Collecting tensorflow==2.18.0
Using cached tensorflow-2.18.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.1 kB)
Requirement already satisfied: keras==3.9.0 in /opt/conda/lib/python3.12/site-packages (3.9.0)
Requirement already satisfied: absl-py>=1.0.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (2.4.0)
Requirement already satisfied: astunparse>=1.6.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (1.6.3)
Requirement already satisfied: flatbuffers>=24.3.25 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (25.9.23)
Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (0.7.0)
Requirement already satisfied: google-pasta>=0.1.1 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (0.2.0)
Requirement already satisfied: libclang>=13.0.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (18.1.1)
Requirement already satisfied: opt-einsum>=2.3.2 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (3.4.0)
Requirement already satisfied: packaging in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (25.0)
Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.3 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (5.29.6)
Requirement already satisfied: requests<3,>=2.21.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (2.33.1)
Requirement already satisfied: setuptools in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (82.0.1)
Requirement already satisfied: six>=1.12.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (1.17.0)
Requirement already satisfied: termcolor>=1.1.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (3.3.0)
Requirement already satisfied: typing-extensions>=3.6.6 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (4.15.0)
Requirement already satisfied: wrapt>=1.11.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (1.17.3)
Requirement already satisfied: grpcio<2.0,>=1.24.3 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (1.73.1)
Requirement already satisfied: tensorboard<2.19,>=2.18 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (2.18.0)
Requirement already satisfied: numpy<2.1.0,>=1.26.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (1.26.4)
Requirement already satisfied: h5py>=3.11.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (3.16.0)
Requirement already satisfied: ml-dtypes<0.5.0,>=0.4.0 in /opt/conda/lib/python3.12/site-packages (from tensorflow==2.18.0) (0.4.1)
Requirement already satisfied: rich in /opt/conda/lib/python3.12/site-packages (from keras==3.9.0) (14.3.3)
Requirement already satisfied: namex in /opt/conda/lib/python3.12/site-packages (from keras==3.9.0) (0.1.0)
Requirement already satisfied: optree in /opt/conda/lib/python3.12/site-packages (from keras==3.9.0) (0.19.0)
Requirement already satisfied: charset_normalizer<4,>=2 in /opt/conda/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.18.0) (3.4.7)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.18.0) (3.11)
Requirement already satisfied: urllib3<3,>=1.26 in /opt/conda/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.18.0) (1.26.20)
Requirement already satisfied: certifi>=2023.5.7 in /opt/conda/lib/python3.12/site-packages (from requests<3,>=2.21.0->tensorflow==2.18.0) (2026.2.25)
Requirement already satisfied: markdown>=2.6.8 in /opt/conda/lib/python3.12/site-packages (from tensorboard<2.19,>=2.18->tensorflow==2.18.0) (3.10.2)
Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in /opt/conda/lib/python3.12/site-packages (from tensorboard<2.19,>=2.18->tensorflow==2.18.0) (0.7.0)
Requirement already satisfied: werkzeug>=1.0.1 in /opt/conda/lib/python3.12/site-packages (from tensorboard<2.19,>=2.18->tensorflow==2.18.0) (3.1.8)
Requirement already satisfied: markupsafe>=2.1.1 in /opt/conda/lib/python3.12/site-packages (from werkzeug>=1.0.1->tensorboard<2.19,>=2.18->tensorflow==2.18.0) (3.0.3)
Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/conda/lib/python3.12/site-packages (from rich->keras==3.9.0) (4.0.0)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/conda/lib/python3.12/site-packages (from rich->keras==3.9.0) (2.20.0)
Requirement already satisfied: mdurl~=0.1 in /opt/conda/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich->keras==3.9.0) (0.1.2)
Using cached tensorflow-2.18.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (615.5 MB)
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
Installing collected packages: tensorflow
Attempting uninstall: tensorflow
Found existing installation: tensorflow None
error: uninstall-no-record-file

× Cannot uninstall tensorflow None
╰─> The package’s contents are unknown: no RECORD file was found for tensorflow.

hint: You might be able to recover from this via: pip install --force-reinstall --no-deps tensorflow==2.19.1
Note: you may need to restart the kernel to use updated packages.
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
Note: you may need to restart the kernel to use updated packages.
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
WARNING: Ignoring invalid distribution ~pmath (/opt/conda/lib/python3.12/site-packages)
Note: you may need to restart the kernel to use updated packages.

Cell below :
from datasets import load_dataset
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig, TrainingArguments, Trainer
import torch
import time
import evaluate
import pandas as pd
import numpy as np

Error Below

TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 from datasets import load_dataset
2 from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig, TrainingArguments, Trainer
3 import torch

File /opt/conda/lib/python3.12/site-packages/datasets/_init_.py:18
1 # ruff: noqa
2 # Copyright 2020 The HuggingFace Datasets Authors and the TensorFlow Datasets Authors.
3 #
(…)
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 _version_ = “2.17.0”
—> 18 from .arrow_dataset import Dataset
19 from .arrow_reader import ReadInstruction
20 from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder

File /opt/conda/lib/python3.12/site-packages/datasets/arrow_dataset.py:66
63 from multiprocess import Pool
64 from tqdm.contrib.concurrent import thread_map
—> 66 from . import config
67 from .arrow_reader import ArrowReader
68 from .arrow_writer import ArrowWriter, OptimizedTypedSequence

File /opt/conda/lib/python3.12/site-packages/datasets/config.py:83
71 for package in [
72 “tensorflow”,
73 “tensorflow-cpu”,
(…)
80 “tensorflow-macos”,
81 ]:
82 try:
—> 83 TF_VERSION = version.parse(importlib.metadata.version(package))
84 except importlib.metadata.PackageNotFoundError:
85 continue

File /opt/conda/lib/python3.12/site-packages/packaging/version.py:56, in parse(version)
47 def parse(version: str) → Version:
48 “”“Parse the given version string.
49
50 >>> parse(‘1.0.dev1’)
(…)
54 :raises InvalidVersion: When the version string is not a valid version.
55 “””
—> 56 return Version(version)

File /opt/conda/lib/python3.12/site-packages/packaging/version.py:200, in Version._init_(self, version)
189 “”“Initialize a Version object.
190
191 :param version:
(…)
196 exception will be raised.
197 “””
199 # Validate the version and parse it into pieces
→ 200 match = self._regex.search(version)
201 if not match:
202 raise InvalidVersion(f"Invalid version: {version!r}")

TypeError: expected string or bytes-like object, got ‘NoneType’

Thank you for the assistance in advance.

hi @The_Scalpel

the error happens because of a broken tensorflow installation in the environment when the datasets library tries to check the tensorflow version it gets none and fails

please try these steps to fix the environment

1 go to the top menu and click kernel then restart kernel

2 do not run the pip install cells again. the lab environment should already have the correct versions

3 if the error persists you need to reset the lab to its original state. go to help then lab help and click get latest version

4 before running any code again restart the kernel one more time and run the import cell.

this should clear the package conflict ,let me know if it works

Hi,

Could you please try clearing the output, restarting the kernel, and then running all the cells again?

If you’re still facing issues with importing the libraries, it might be due to updates or changes over time. In that case, please let me know so we can inform QA and have them look into fixing it.
Thanks.

Hi - I tried all of the above and it’s still not working. I installed everything locally on my machine and the issue was due to versioning of the packages & python version.

Very frustrating having had to pay extra for this.

Hello, I am facing the same import issues in Week 1, Lab1 of this course. I tried restarting the kernel and running the cells again multiple times. Does not work.

In this set of instructions. Where can I find “Lab help”? I do not see the option of “Click the latest version” . Thank you for your help.

“Lab Help” is the question-mark inside a circle, in the upper right corner of the browser page. Click on it to see the “Get latest version” tool.

Note: Before you can “get the latest version”, you must either delete or rename your existing notebook ipynb file. The “Get latest version” tool only replaces missing files - it will not over-write an existing file.

Hi everyone and thank you for reporting! We will look into this and update the labs if needed. Please monitor this topic for updates.

1 Like

Hi everyone. The labs are now fixed. Please reopen them from the classroom to get the latest version. Thanks!

1 Like