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

Anaconda新环境下Jupyter/Pandas无法读取CSV文件的路径问题求助

Troubleshooting Pandas FileNotFoundError in New Anaconda Python 3.6 Environment

Hey there, let's work through this CSV file issue together—since you're using a fresh Anaconda environment for Python 3.6, the problem is likely tied to either Jupyter's working directory, kernel misconfiguration, or a small path-related oversight. Here's how to fix it step by step:

1. Verify Jupyter's Current Working Directory

First, let's confirm where Jupyter is looking for files. Run this code in your Jupyter notebook:

import os
print(os.getcwd())

This will output the folder Jupyter is currently using as its root. If returns.csv isn't in this folder, that's the first problem! You have two quick fixes here:

  • Move your returns.csv file directly into the folder printed by os.getcwd(), or
  • Use the full absolute path to your file when calling pd.read_csv() (more on this below).

2. Fix Anaconda Environment-Jupyter Kernel Misalignment

Sometimes even if you activate your new Python 3.6 environment, Jupyter might still be using your default environment's kernel—this can cause path inconsistencies. Let's fix that:

  • Open your terminal/command prompt and activate your Python 3.6 environment:
    conda activate your_env_name
    
  • Install the IPython kernel into this environment:
    conda install ipykernel
    
  • Register this environment as a Jupyter kernel:
    python -m ipykernel install --user --name your_env_name --display-name "Python 3.6 (your_env_name)"
    
  • Restart Jupyter Notebook, then select the new Python 3.6 (your_env_name) kernel from the "Kernel > Change Kernel" menu before trying to read the CSV again.

3. Double-Check File Paths, Spelling, and Permissions

  • Case sensitivity: On macOS/Linux, Returns.csv and returns.csv are treated as different files—make sure your filename matches exactly what you're typing in the code.
  • Windows path formatting: If you're on Windows, absolute paths need special handling. Either use double backslashes:
    df_returns = pd.read_csv('C:\\Users\\YourUsername\\Desktop\\returns.csv')
    
    Or use a raw string (add an r before the path):
    df_returns = pd.read_csv(r'C:\Users\YourUsername\Desktop\returns.csv')
    
  • File permissions: If your CSV is in a system-protected folder (like Program Files), move it to a personal folder (e.g., Documents or Desktop) where you have full read access.

4. Test the Absolute Path Explicitly

If you're still getting the error with an absolute path, print the path first to confirm it's correct:

file_path = "/full/path/to/returns.csv"  # Replace with your actual path
print(file_path)
df_returns = pd.read_csv(file_path)

Then manually navigate to that path in your file explorer to ensure the file exists there.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:30:14