'ModuleNotFoundError virtual environment pythonanywhere in scheduled task

I am trying to schedule a task, but when running the script I get:

ModuleNotFoundError: No module named 'clients' 

Even this is an installed app within my django project. I already added a hashbang/shebang as:

  1. #!/usr/bin/venv python3.9
  2. #!/usr/bin/python3.9

Either option gets me the same error message. I think my code for the schedule task is good, but here it is anyways:

cd /home/myusername/myproject/maintenance && workon venv && python3.9 mantenimientosemanal.py

Any help will be really appreciated. Thanks.



Solution 1:[1]

Ok, after reading a lot, for some reason there is something related to WSGI, sys.path that I don't know yet but I found out this can be solved by creating a custom django-admin commands and then running this python manage.py mycustomcommand as a scheduled task and voila!! It worked!! Thanks and hope this help others.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adrian