Jocke
Jocke

Reputation: 83

Python execution works in Shell but not in Terminal

I have a Raspberry Pi and I'm attempting to create a Python script. However the issue is that I'm unable to run the script from the Terminal, it throws syntax errors yet the same code works just fine in the Python 3.5.3 Shell.

I'm trying the simplest thing such as a printand I've tried various ways with the parentheses and quotation marks, yet no luck with executing the script in the terminal.

I'll include a simple Imgur link of a screenshot, showing how the code is successfully executed in the Shell but not in the terminal.

https://i.sstatic.net/JEi5k.jpg

The code:

print ("test")

Any assistance is greatly appreciated in advance!

Upvotes: 0

Views: 715

Answers (2)

ralf htp
ralf htp

Reputation: 9432

you can execute python scripts, i.e. the script boa.py from terminal by python boa.py

Upvotes: 0

Julio Daniel Reyes
Julio Daniel Reyes

Reputation: 6365

The error was that your terminal didn't know that the code you tried to execute was python, therefore it tried to execute it with the bash interpreter.

Adding the correct shebang to specify the use of the python interpreter fixed the problem.

#!/usr/bin/env python 

print("test")

Upvotes: 2

Related Questions