Forums

Using dotenv with python script?

I have a simple python script that I am trying to run once a day. I keep getting this error in the task log:

from dotenv import load_dotenv ModuleNotFoundError: No module named 'dotenv'

I've been doing some searching and it looks like I may need to make a virtual environment. I did the whole mkvirtualenv my-virtualenv and did pip install python-dotenv, but now I'm not sure how to run my python script using this virtual environment so that it has the modules it needs. Do I need to put something in my script to somehow "link" it? Or do I need to set up my files in a way so that when the scheduler gets the file to run from the file path, it just knows to use the virtual environment with dotenv? Thank you!

Check out the help page on scheduled tasks -- there's a section about half-way down on using a virtualenv.