ModuleNotFoundError: No module named 'schedule'

I have python program that imports schedule (import schedule) at the beginning. The code executes without a problem with python3 command, but starting it from other python file with call("sudo python3", shell=True) returns error ModuleNotFoundError: No module named 'schedule'. And I can't figure out why...

I have library schedule installed with pip, pip3 AND apt-get (tried all three just to be sure :)


🔴 No definitive solution yet

📌 Solution 1

Because you are using a different interpreter/virtual environment for each project, which is generally considered the best practice.

You can apply the command below to create a file with all your installed modules, so you can use them whenever you want, by a single command to install all.

To keep/save all modules in a file:

pip freeze > requirements.txt

To install all of them with a single command in a new interpreter/virtual environment:

pip install requirements.txt

📌 Solution 2

You can try to force the usage of the same python interpreter with :

call(f"sudo {os.getenv('PYTHON3')}", shell=True)

and call with :

PYTHON3=$(type python3) ...