Question

ModuleNotFoundError: No module named 'dotenv' but pip says it's installed??

Solved · 2601 viewsasked by jakeypoo

Also the Run button in Cursor gives the same. Losing my mind a bit.

What I’ve tried

Installed it again, installed "dotenv" too (other package), restarted Cursor.

Comment
What do which python and which pip print? marco_py

3 answers

Marked as helpful by the asker
marco_py

Your pip and your python are different Pythons. Check:

which python; which pip
python -c "import sys; print(sys.executable)"

Fix it for good with a virtual environment per project:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install python-dotenv

Always install with python -m pip, then it goes to the Python you run. In Cursor: Cmd+Shift+P → "Python: Select Interpreter" → pick .venv, so the Run button uses it too. And uninstall that other dotenv package, it's not the one you want.

Comment
which python pointed to some old anaconda thing i installed in 2021. venv fixed it. thank you so much jakeypoo
python -m pip should be the first thing anyone learns honestly sam_builds
Sending this link to half my friends nightshiftbuilder
wes_codes

python -m pip is the whole answer. Everything else is detail.

Comment
ingrid_h

Cursor-specific: once the interpreter is selected, new terminals should activate the venv automatically (python.terminal.activateEnvironment setting). If your prompt doesn't show (.venv), that's why python still points somewhere else.

Comment