Forums

No module error, only for schedule tasks

Hi, when I run the script from the scehduler I get:

ImportError: No module named pymysql

But if I run it from the console it works!

Can you help me?

Gregorio

It might be due to the wrong version of Python being used. If you delete the failing scheduled task, and replace it with one that specifies the Python version -- for example:

python3.5 path/to/script.py

...then that should fix the problem

[formatted by admin]

10:21 ~ $ python --version
Python 2.7.12
10:21 ~ $ workon python01
(python01) 10:32 ~ $ python --version
Python 3.6.9
(python01) 10:32 ~ $
  • point 1. which python version you are talking about?

  • point 2. python2.7 /home/vishnuji/hello/world/views.py python3.6 /home/vishnuji/hello/world/views.py Both are not working

/home/vishnuji/hello/world/views.py this is path.

please clearly explain.

If the script needs a virtualenv, you should use Python from that venv: https://help.pythonanywhere.com/pages/VirtualEnvInScheduledTasks/

Hi there,

Having a similar problem for always on task - cannot for life of me get an always on task to correctly fine a module, even when cd ing into the right folder

cd /home/canonburygroup/aiB/ && python3.8 -u main_files/audio/transcription.py

Error: ModuleNotFoundError: No module named 'main_files'

Let me know, main thanks

Do you have main_files module in /home/canonburygroup/aiB/main_files/audio/ directory?

Hi - main_files is in the aiB directory which is why I am cd'ing into that directory first.

Am I missing something basic here?

Many thanks,

The module you want to import needs to be in PYTHONPATH environment variable or in the same directory as the script you're running, so changing working directory won't help. You need to add relevant paths to PYTHONPATH (you can do it either in the command, or inside the script). See Python docs.