Forums

Scheduler cannot find imported module

I have reach almost every article pertaining to the scheduler and module errors. I have not been able to find a solution.

Problem: I am getting Module Not Found error when I schedule my script to run. The script runs fine from Bash, and all other options of running it. Only when it is scheduled, it does not find the module.

Here is the exact error:

Traceback (most recent call last):

  File "/home/USERNAME/GA_script/GA_python.py", line 6, in <module>

    import googleanalytics as ga

ImportError: No module named 'googleanalytics'

The first few lines of code:

1
2
3
4
5
6
#!/usr/bin/python3
import json
import googleanalytics as ga
import smtplib
import logging
import time

I am not using virtualenv. I installed 'googleanalytics' module via this command:

pip3 install --user googleanalytics

The install was successfully.

I schedule via this command:

python3 /home/USERNAME/GA_script/GA_python.py

If I type in this same command into Bash, it works perfectly.

Any assistance would be great! I am completely out of ideas.

Hmm, interesting. I'm wondering if it's picking up different versions of Python 3 in different places -- we have 3.3, 3.4 and 3.5 installed. What happens if you schedule with the full version, ie.

python3.5 /home/USERNAME/GA_script/GA_python.py

...?

Hey! That worked perfectly!

Should I always use python3.5 to test my script and schedule it?

Yes, I'd recommend you do. It's always best to know exactly which version of Python is being used, just in case a system default changes in the future.