I Have Installed Python-Dotenv but Python Cannot Find It
I Am Using Dotenv in a Flask Project, and Have Also Tested This in a Dumbed Down Test Environment as Well. I Have Tried Uninstalling and Reinstalling Etc but...
i am using dotenv in a flask project, and have also tested this in a dumbed down test environment as well. I have tried uninstalling and reinstalling etc but the dotenv module cannot be found by python.
When starting flask it sees there are some .env files and tells me to install dotenv even though it is installed and i can see it in flasks system libraries.
When I run code I get a module not found error saying it can't find dotenv. The code is
import os
from dotenv import load_dotenv
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
and the error is
Any advice gratefully accepted.
3 Answers
It's possible that you also have the "dotenv" package installed.
In your virtual environment, try:
pip uninstall dotenv
pip uninstall python-dotenv
pip install python-dotenv
Also you may have dotenv installed at the system level (outside of your virtual environment). If yes, you could try uninstalling that.
If this is not the issue then please post your code and the resultant error.
It turns out there were a number of problems with my code and I will briefly list them here in case anyone else experiences the same problems.
Must Read
1st Problem
Being reasonably new I am not really clear how the python ecosystem I have installed all hangs together. I have installed Anaconda and Spyder as my development environment. However I have been following a Flask tutorial that uses pip as the installer with virtual environments. The command prompt I use is the one that came with Anaconda. Everything seemed to be working OK somehow, until I got the dotenv problem, which is in fact a tiny detail in the over-all rather large tutorial.
To fix dotenv I was trying all sorts of install/uninstalls with pip, I could see dotenv was installed already! That didn't work. What did work was installing dotenv with conda in my command prompt, but I had to be explicit about where to get dotenv from. The command that worked was
conda install -c conda-forge python-dotenv