Forums

Trouble working with Virtual Environment and Scheduler

Hi there - I have a python script that I wanted to run each day using the scheduler - the output is an html file.

I set up a virtual environment to ensure I have all the right packages installed: (myvirtualenv)

When I am in the virtual environment in Bash and run the script it outputs the html file......if the file already exists - it just overwrites the file.....so I wanted to get this task scheduled. When I looked at the topic 'Using a virtualenv in a scheduled task' https://help.pythonanywhere.com/pages/VirtualEnvInScheduledTasks/ I noticed that I needed to put the path of the virtual environment before my file name with ONE space in between the two....I think that I have the correct pathing down for all of this:

/home/robotamp/.virtualenvs/myvirtualenv/bin/python3.7 /home/robotamp/plotly_scripts/eia_api_cl_supply_refining.py


when I schedule the task it has a return code of 0 2021-03-17 16:08:13 -- Completed task, took 9.01 seconds, return code was 0.

I believe the return code of 0 means that it couldn't find the virtual environment....I tried both python and python3.7 at the end of the file.....

Anyone know how I can resolve this?

Thanks so much!!!

That message and return code mean that the task ran successfully and completed in 9.01 seconds. If the code is writing to a file and it's not where you expect it to be, see https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

Hi Glenn - thanks for the note! I found my error <insert user error here>

The file did save but not in the expected directory - it is saving to the master directory.....so it looks like it all worked!