0

I do not know why but I cannot run a python script though the terminal.

my script:

define_regions.py

print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'

terminal:

pik:scripts katja$ python define_regions.py
pik:scripts katja$

It does not execute it somehow and I do not understand why.

Thank you in advance.

EDIT:

pik:scripts katja$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

python -V
Python 2.7.6

pik:scripts katja$ which python
/usr/local/bin/python

pik:scripts katja$ python -c "print 'hello' "
hello

EDIT2: modification to a script did not work either

#!/usr/local/bin/python    
print "Hello World!"
Jens
  • 15,326
  • 9
  • 51
  • 75
Anni
  • 363
  • 4
  • 15

2 Answers2

0

did you try to open python terminal (just to check python is running?): type python and enter

and are you in the folder where your script is?

(do a list (ls) command to check you see the script file, otherwhise, use cd to change dir to the location of the script)

sometimes you need to put a point before a script you run (in linux, but os x is very simular) so python ./define_regions.py

can you put:

#!/usr/bin/python

on top of your file?

How did you create the file? not very known with os x editors.... but you need to use the most simple editor... to avoid all kind of non ascii chars in the file (like line ends...).

michel.iamit
  • 5,264
  • 8
  • 49
  • 73
-1

Add shebang line in the beginning your python script

#!/usr/bin/env python 

and make your python script executable using chmod from shell.

chmod +x define_regions.py

then you will be able to execute your python script like you were trying to achieve.

Adding the shebang means people can invoke the script directly if they want (assuming it's marked as executable); omitting it just means python has to be invoked manually.

The end result of running the program isn't affected either way; it's just options of the means.

Community
  • 1
  • 1
Ciasto piekarz
  • 6,378
  • 11
  • 59
  • 149