PyCharm中路径声明失效问题求助
Hey there, let's troubleshoot that error you're seeing when running movies.py! Based on your setup and the traceback snippet, this is almost definitely a file path issue—your code is looking for ratings.csv in the wrong place.
First, Let's Confirm Your Folder Structure
Right now, your project setup looks like this:
collaborative filtering/ ├── movies.py └── ml-latest-small/ ├── ratings.csv ├── movies.csv └── (other CSV files from the dataset)
The problem is: your code is trying to load ratings.csv directly from the collaborative filtering root folder, but the file is actually tucked inside the ml-latest-small subfolder.
Two Simple Fixes
Option 1: Update the file path in your code
Modify thefrom_csvcall to include the subfolder path. If your original line was:cf = CollabFilterDataset.from_csv(path, 'ratings.csv', 'userId', 'movieId')Change it to:
cf = CollabFilterDataset.from_csv(path, 'ml-latest-small/ratings.csv', 'userId', 'movieId')This tells the code to look inside the
ml-latest-smallfolder for the CSV, which keeps your project structure organized.Option 2: Move the CSV files to the root folder
If you prefer a simpler (though less tidy) fix, just drag all the CSV files fromml-latest-smallinto the same folder asmovies.py. Your original code will then find the files without any changes.
Quick Extra Check: Verify PyCharm's Working Directory
Sometimes PyCharm uses a different working directory than you expect, which can throw off file paths. To confirm:
- Click the dropdown next to the green run button in the top-right corner of PyCharm
- Select Edit Configurations...
- In the window that pops up, check the Working directory field—make sure it's set to the absolute path of your
collaborative filteringfolder (e.g.,/Users/usernamehere/Desktop/Machine Learning/Lesson 5/CollaborativeFiltering)
内容的提问来源于stack exchange,提问作者user9366862

