[Answered ]-How do I get around ModuleNotFoundError: No module named 'dot env

0👍

The answer to the original question is to run pip install python-dotenv (PyPI link) as opposed to pip install dotenv, a package that hasn’t been updated since 2018, as seen in the Github link.

Now for the KeyError you ran into.

KeyError means it didn’t find the key SECRET_KEY, which from your screenshots is probably because there is no .env file that I can see. Just create a file called .env (NOTE, it must be called .env with a . and not just env), and this is where you will store secret keys (which hopefully you won’t post on StackOverflow). Something like this:

# .env

SECRET_KEY=aBcDeFgHiJkLmNoPqRsTuVwXyZ123456789
DATABASE_PASSWORD=aVeryStrongDatabsePassword
ANOTHER_KEY=ujhgasdhfcdahfda123794123472314723judh

# Any other variables you need to keep secret

You can easily generate long, secure passwords and keys using secrets.

Finally, please copy and paste code. Do not use screenshots for this. Checkout why should I not use screenshots? And checkout this link, 5 Ways to Embed Code in StackOverflow if you’re not sure how.

1👍

It seems to me that when I tried setting up my secret_key via Zach Plauchè’s answer I used one of the other techniques the others set up. When I ran purely off of his method that he first mentioned it worked for me.

https://stackoverflow.com/a/61437799/17598401

it seems i need to learn more about environment variables and secret key set ups. for the time being I am satisfied with the workaround and will continue through the polls app tutorial.

Leave a comment