Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-11-22
8
Medium Priority
?
345 Views
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.
0
Comment
Question by:Doug Brennaman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 20

Expert Comment

by:simon3270
ID: 40459483
Are you running it as
    python script.py
or
   python3 script.py

(in case pytz is only installed in Python3)
0
 
LVL 12

Accepted Solution

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

type

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

#!/path/to/python3

Open in new window


then you should be able tu run it with ./scriptname.py
0
 

Author Comment

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

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.
0
 
LVL 20

Expert Comment

by:simon3270
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!
0
 

Author Closing Comment

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

Author Comment

by:Doug Brennaman
ID: 40462724
simon,
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.
0
 
LVL 20

Expert Comment

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

And welcome to EE.
0
Question has a verified solution.

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

1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

721 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