This error is an ImportError caused by a name collision, compounded by an incorrect file path.Python is trying to import TopicalDocuments from the popular Hugging Face datasets library (which is installed in your venv at .../site-packages/datasets), but that library does not contain an object named TopicalDocuments.You are trying to import TopicalDocuments from your own custom module, which also happens to be named datasets (likely a file named datasets.py). This custom file is located in the itamars_script_soft_topics directory, but Python isn't finding it correctly.Here is how to fix it.Problem 1: Incorrect PathYour code has a typo in the path you're adding.Your comment says: # add path to /XXXitamars_script_soft_topics/Your code says: sys.path.append('/nashim/itamars_script_soft_topics')The code version is missing the /home/esther/PycharmProjects/edut710 prefix. You need to fix this line first.Fix:
Change this line:Pythonsys.path.append('/nashim/itamars_script_soft_topics')
To this:Pythonsys.path.append('/XXXitamars_script_soft_topics')
Problem 2: Import Name Collision (The Real Issue)Even after fixing the path, you will likely still have the error. This is because Python searches paths in order, and it will find the installed datasets library in your site-packages before it finds the custom datasets.py module you just added to the path.You have two ways to solve this.Solution A (Recommended): Rename Your Custom ModuleThe best practice is to avoid naming your custom files the same as popular, installed libraries.Go to the directory:
/XXXitamars_script_soft_topics/Rename your datasets.py file to something more specific, like topic_datasets.py.In your main script (derive_categories.py), change the import statement to use the new name:Pythonimport sys
Add the correct path
sys.path.append('/XXXitamars_script_soft_topics')
import os
import pandas as pd
Import from your renamed file
from topic_datasets import TopicalDocuments
from soft_topics_generator import TitleSetGenerator
Solution B (Quick Fix): Force Your Path to the FrontIf you cannot rename the file, you can force Python to look in your custom directory first by using sys.path.insert instead of sys.path.append.Pythonimport sys
Insert your custom path at the beginning of the list
sys.path.insert(0, '/XXXitamars_script_soft_topics')
import os
import pandas as pd
from datasets import TopicalDocuments
from soft_topics_generator import TitleSetGenerator
Warning: This is generally bad practice. It "shadows" the real datasets library, meaning that if any part of your project (or soft_topics_generator) does need to use the Hugging Face datasets library, it will fail. Solution A is much safer.