Forums

No module name dotenv

I just started to integrate my web app with python anywhere. I added dotenv by activating my virtual environment and running the command pip install python-dotenv. I get the no module named dotenv error even though I've looked in my virtual environment's site-packages folder and I see dotenv folder. Anyone knows what's up?

Where are you seeing that error? Is it in a console, in your website's error log, or perhaps somewhere else?

I'm in same problem. If you figured out how to solve it, let me know

You need to import dotenv and call load_dotenv() in the wsgi.py file.

I'm in the same problem. It seems to call load_dotenv() does not work for me.

What I have done

I have followed this forum about secret key. So, saved environment variables, installed python-dotenv, updated WSGI file, and post activated .env file on my virtual environment.

problem

I still see this problem.

  • 2020-08-30 03:22:01,481: Error running WSGI application
  • 2020-08-30 03:22:01,485: ModuleNotFoundError: No module named 'dotenv'
  • 2020-08-30 03:22:01,485: File "/var/www/wayway_pythonanywhere_com_wsgi.py", line 5, in <module>
  • 2020-08-30 03:22:01,485: from dotenv import load_dotenv

Does anyone know how I can fix this? Thanks.

You need to install python-dotenv into the virtualenv/version of Python that you are using for your web app. That's the second step on that page.

Yes, I have done it already.

  • save my environment variables into a .env file
  • Install python-dotenv into my virtual env
  • updated WSGI file
  • post-activated .env file on my virtual environment

And I confirmed that I have installed python-dotenv.

--(myvirtualenv) 03:20 ~ $ pip install python-dotenv
--Looking in links: /usr/share/pip-wheels
--Requirement already satisfied: python-dotenv in ./.virtualenvs/myvirtualenv/lib/python3.6/site-packages (0.14.0)

But I still get the error log...

Are you sure that your webapp is using that virtualenv?

Sorry, it seems I didn't use that virtualenv... I guess I can move forward. thanks for your advice.

OK -- do let us know if you have any further problems.

Bumping this thread because I have the same issue. No module found, and my webapp has the same path to my virtual environment as dotenv. I'm wondering if there is a conflict between the wsgi.py file created by Django and the one that is created by pythonanywhere?

If you have not installed dotenv in the virtualenv that your web app is using, then you'll get this message. It has nothing to do with the wsgi file.

It is installed. I checked in the virtual environment's lib folder, and I see it. The virtual environment path for my webapp matches the one in the .virtualenv folder. Just to double check, I clicked the start console from virtualenv and ran pip freeze which it appeared as the correct version. I tried deleting the virtual environment and starting from scratch, but it still cannot find the dotenv module.

I tried in my virtualenv python -i /var/www/mysite_com_wsgi.py as suggested on the debugging help page, and got an error about the SECRET_KEY being empty. The SECRET_KEY is an environment variable in the .env file, which is dependent on dotenv.

Ok. What is the error that you're getting, then?

2022-03-06 20:37:07,150: Error running WSGI application 2022-03-06 20:37:07,154: ModuleNotFoundError: No module named 'dotenv'

My wsgi.py file has the lines (replaced myapp with my app name): project_folder = os.path.expanduser('~/myapp') load_dotenv(os.path.join(project_folder, '.env')) before the call to get wsgi application.

The working directory for this webapp is /home/username if that helps.

I apologize, I was looking at the earlier logs and the latest shows that it has found dotenv.

No problem -- glad you figured that out!

I ran into a similar problem, trying to create a virtual environment. I ran python -i /var/www/drbarak_pythonanywhere_com_wsgi.py and got an error No module named 'mysql', although when I tried to install it, using pip install mysql, it says it is already installed, and "pip list" shows it is installed and it's is version 0.0.3

Normally you should install mysqlclient library.

i integrated my app with Pythonanywhere and it has been working just fine not until when i want to add my environment variables. I have gone through the steps, i have installed the dotenv, confirm the installation, but it is always giving error whenever i am importing it in my wsgi.file

Error running WSGI application ModuleNotFoundError: No module named 'dotenv' File "/var/www/weberdeveloper_pythonanywhere_com_wsgi.py", line 2, in <module> from dotenv import load_dotenv

It is always giving this report.

You need to install python-dotenv into the virtualenv/version of Python that you are using for your web app. Check the second step here and make sure that you're installing it in the environment that you web app is using.

hi, im having the same problem with the dotenv module, i already install the python-dotenv into my virtual env, i modified the wsgi, i put the path of my virtual env in the section of the web tab 'virtualenv' and still after reload the page several times it gives me the same error:

Error running WSGI application ModuleNotFoundError: No module named 'dotenv' File "/var/www/jeipi2_pythonanywhere_com_wsgi.py", line 16, in <module> from dotenv import load_dotenv

Make sure that you're looking at the bottom of the error log, since the most recent entries show there.

I had this after moving to python 3.8 using the fishnchip system image. pip list showed it was using dotenv v1.0.0 after updating the packages.

FIX:

pip install python-dotenv==0.14.0 (NOTE: This was a version I was using previously which worked :))