how do I make a python program run from a bash shell?

Posted on 2014-11-22
Last Modified: 2016-08-13
on a raspberry pi I have a python script which runs without error from within Idle3 (sudo /usr/bin/idle3) When I try to run it from a shell script it fails with the error message "ImportError: No module named pytz".  It has no problem finding the other modules (picamera, time, and datetime)  I installed the pytz package using apt-get.
My searches have yielded suggestions relating to PATH, python installation etc. I cannot find documentation that has helped.
Question by:Doug Brennaman
  • 4
  • 3
LVL 19

Expert Comment

ID: 40459483
Are you running it as

(in case pytz is only installed in Python3)
LVL 11

Accepted Solution

andreas earned 500 total points
ID: 40459860
Im guessing you are using the wrong shebang.


which python3

Open in new window

e.g. the command yields /path/to/python3

and use its output as the shebang for the script and try again.

1st linx of the script should look like


Open in new window

then you should be able tu run it with ./

Author Comment

by:Doug Brennaman
ID: 40460521
thank you.  That was the problem.  And thanks for providing the steps to correct it,

Author Comment

by:Doug Brennaman
ID: 40460593
I've requested that this question be closed as follows:

Accepted answer: 0 points for Doug Brennaman's comment #a40460521

for the following reason:

The answer was educational.  I now know the reason for the error as well as the steps to solve it.
LVL 19

Expert Comment

ID: 40460594
Doug, I think you may have selected the wrong answer. Whether or not you give any points to me, you should at least give some to Andreas!

Author Closing Comment

by:Doug Brennaman
ID: 40462717
Answer is informative, explained the problem and provided a fix.

Author Comment

by:Doug Brennaman
ID: 40462724
thanks for pointing that out.  I did make a mistake in accepting my own comment as the answer.  I have accepted Andreas's answer.  
This is the first time I've posted a question so I was unfamiliar with the process.
LVL 19

Expert Comment

ID: 40463184
No problem - we were all beginners once!

And welcome to EE.
Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux : taking backup different mount points under the same directory 8 48
Access_log 17 100
nagios monitor 3 42
su - oracle could not open session 6 50
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now