Home > database >  ModuleNotFoundError: No module named 'schedule'
ModuleNotFoundError: No module named 'schedule'

Time:08-07

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 ProgramWithSchedule.py", 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 :)

Thanks!

CodePudding user response:

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

CodePudding user response:

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

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

and call your-script.py with :

PYTHON3=$(type python3) your-script.py ...
  • Related