Forums

Always-On Task Error

Hi, I have a project (by a dev) that I run on VM. I am trying to run it on PythonAnywhere (Always-On Task).

Usually the way I activate the script is by typing python3 -m configname.main. The config is in .toml format and not .py.

I tested the said command in the bash console and it worked properly.

However, I am unable to run it via Always-On Task.

I tried various commands including:

python3 /home/user/folder/configname.main (moduleNotFoundError)

python3 /home/user/folder/configname.toml (Syntax Error: Invalid Syntax, it's regarding "=")

python3 -m /home/user/folder/configname.main (not running)

python3 -m /home/user/folder/configname.toml (not running)

Thanks!

Take a look at what -m is doing, https://docs.python.org/3.10/using/cmdline.html#cmdoption-m and compare it to your case.

Hi, I am not a dev so I will not be able to understand how things work. I am just trying to host a project that was made by a dev. But I will try to explain the best I can.

The project is a python package with modules which is why -m is needed when initiated via bash console.

My absolute path to the folder is /home/rena/project1 where the file1.toml file is located at.

Then there's a subfolder containing a number of .py file including main.py.

So like I said activating the script via bash console worked. I opened the bash console while I am on the said project1 folder directory and then typed python3 -m file1.main.

I am assuming this activates the main.py contained within the subfolder.

So I tried this command (Always On Task): python3 -m /home/rena/project1/subfolder/main. This command produced this error:

2024-12-06 13:31:43 - Task preparing to start Dec 6 13:33:41 /home/rena/.local/bin/python: No module named /home/rena/project1/subfolder/main.

I tried with .py extension. Python3 -m /home/rena/project1/subfolder/main. It produced this error:

2024-12-06 13:43:15 - Task preparing to start Dec 6 13:43:44 /home/rena/.local/bin/python: Error while finding module specification for '/home/rena/project1/subfolder/main.py' (ModuleNotFoundError: No module named '/home/rena/project1/subfolder/main'). Try using '/home/rena/project1/subfolder/main' instead of '/home/rena/project1/subfolder/main.py' as the module name.

Please assist. Thank you.

What you pass to -m is not a path to the file but a python path to the module that has to be present in a sys.path See https://docs.python.org/3.10/library/sys.html#sys.path

You may try something like PYTHONPATH=/home/user/folder/ /home/user/.local/bin/python3 -m configname.main assuming that I understand your situation correctly

Why my Task errors? link to image

We had problem with one of our machines. Sorry for that. It should be fine now.