ModuleNotFoundError while following the DVC course

I am following the Iterative Tools for Data Scientists & Analysts course step by step, so far everything was going smoothly, but now I am at task 3.5 and when I am trying to follow along the course and execute dvc repro I get:

ModuleNotFoundError: No module named 'src'
ERROR: failed to reproduce 'dvc.yaml': failed to run: python src/stages/data_load.py --config=params.yaml, exited with 1

I am having same branch and files as in the course so not sure why it is not working.
I tried adding __init__.py to the folder but didn’t help.

Hi SnailTheSnail!

I did some digging in Discord and found this similar messages: Discord

The problem it seems may be the setup with .env. Per the Discord message:
“Tbh, I’m not sure we support the pure setup via .env file with env vars in it. We would need to add the same setting in the config file, or “learn” how to use the existing one. I think this is a related discussion - Improve Python environment activation · Issue #1791 · iterative/vscode-dvc · GitHub … Could you please chime in there?”

You may want to try setup with venv instead. The README has the instructions. This line may help:

echo “export PYTHONPATH=$PWD” >> dvc-venv/bin/activate
source dvc-venv/bin/activate

Let us know if these aren’t fruitful and we will help figure it out!

Hi everyone!

To extend the answer for Windows users (yeah I know, not everybody can be perfect), here is a Medium article that might be useful to others: How to set the PYTHONPATH for your VirualEnv in Windows | by Hojjat | Medium

Bascially, you open the Activate.ps1 file at .\dvc-venv\Scripts\Activate.ps1 and then follow those two steps:

  • Add the following to the deactivate function:
if (Test-Path env:_OLD_VIRTUAL_PATH) {
        copy-item env:_OLD_VIRTUAL_PATH env:PATH
        remove-item env:_OLD_VIRTUAL_PATH
    }
  • Add this to the end of the file:
if (Test-Path env:PYTHONPATH) {
    copy-item env:PYTHONPATH env:_OLD_PYTHON_PATH
}
$env:PYTHONPATH = "$(Resolve-Path "$env:VIRTUAL_ENV\..");$env:PYTHONPATH"

Finally, deactivate and reactivate the environment.

Works like a charm for me.

Thanks @Hojjat!