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

VSCode Conda环境下Jupyter Notebook无法导入src模块求助

Solution for ModuleNotFoundError: No module named 'src'

Root Cause

Your VSCode working directory is set to its own install folder instead of the root of your cloned GitHub repo. Python can't locate the src module because it's not in the current working directory or Python's path.

Fix 1: Set VSCode's Working Directory to Repo Root

  • Open VSCode, go to File > Open Folder, then select the root folder of your cloned repo (the one containing README.md and src on your D盘).
  • Verify by running this in your notebook:
    import os
    print(os.getcwd())
    
    It should output the path to your repo root, not the VSCode install directory. After this, your original import should work without extra code.

Fix 2: Temporarily Add Repo Root to Python Path

If you can't switch the working directory right now, add this code at the very top of your ws-notebook.ipynb:

import sys
import os

# Replace with your actual repo root path on D盘, e.g., "D:/my-cloned-repo"
repo_root = "D:/path/to/your/cloned/repo"

if repo_root not in sys.path:
    sys.path.append(repo_root)

# Now run your import
from src.preprocessing import create_data

Fix 3: Persistent Solution (Install as Editable Package)

For long-term use, install your project as an editable package in your Conda environment:

  1. Open the Conda terminal (make sure your environment is activated).
  2. Navigate to your repo root:
    cd D:/path/to/your/cloned/repo
    
  3. Run:
    pip install -e .
    

This registers your src module with Python, so you can import it from anywhere in the environment without adjusting paths.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 02:35:01