Skip to content Skip to sidebar Skip to footer

Modulenotfounderror When Executing Python Program From Bash Script

I have a script which monitors a directory using inotify-tools. When a new file is added to the directory, the script calls a python program and passes the path and fill name as ar

Solution 1:

How are you launching this script? I'd guess that the user environment you're running in is different from the interactive environment in some way. The most likely cause is that you're setting the PYTHONPATH environment variable differently between these two environments -- try printing that out before running your Python code and seeing if it differs.

Another possibility is that you've got your path set differently in your two environments, and you're not even running the same Python version. Check your PATH environment variable and see if these are the same.

One reason these could be different is if your interactive environment, where the script works, is grabbing these or other configurations from your .profile file. The .profile is only read by login shells, not other shells. Putting these in your .bashrc rather than .profile might make a difference.

(It should go without saying that if you're running as a different user in these two contexts, that the relevant environment variables need to be present in both users' configurations.)

Post a Comment for "Modulenotfounderror When Executing Python Program From Bash Script"