You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyCharm中路径声明失效问题求助

Fixing the File Not Found Error for Your Collaborative Filtering Project

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 the from_csv call 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-small folder 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 from ml-latest-small into the same folder as movies.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:

  1. Click the dropdown next to the green run button in the top-right corner of PyCharm
  2. Select Edit Configurations...
  3. In the window that pops up, check the Working directory field—make sure it's set to the absolute path of your collaborative filtering folder (e.g., /Users/usernamehere/Desktop/Machine Learning/Lesson 5/CollaborativeFiltering)

内容的提问来源于stack exchange,提问作者user9366862

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:50:21