0

Can anyone tell me why i can't run python using ./ but able to use python

-rwxr-xr-x@ 1 xxxx  staff   258 14 Nov 14:08 ltry.py
-rwxr-xr-x@ 1 xxxx  staff  1037 14 Nov 11:20 pdTry.py
 xxxx-MacBook-Pro:python xxxx$ ./ltry.py
 File "./ltry.py", line 10
 print "Hello you"
                 ^
 SyntaxError: invalid syntax
xxxx-MacBook-Pro:python xxxx$ python ltry.py
Hello you
['ltry.py']

Also, i installed python IDLE, but i wan't able to try print, why?

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> print 'eeere'
SyntaxError: invalid syntax
>>> print "helooe"
SyntaxError: invalid syntax
4
  • chmod 755 ltry.py? #!/usr/bin/env python? Commented Nov 14, 2012 at 22:50
  • Did chmod 755. you can see the permissions of my file. Also have #!/usr/local/bin/python3.3 -tt Commented Nov 14, 2012 at 22:53
  • @Fish: Please ask only one question at a time Commented Nov 14, 2012 at 22:55
  • @das_weezul In this case, both questions are probably really different manifestations of the same issue. Commented Nov 14, 2012 at 22:57

2 Answers 2

5

For the second question, you are using Python 3.X there, where the syntax for printing was changed from the 2.X style you are using (print 'string' is print('string') in 3.X). My bet is that for the first question, you have 2 installations of Python on your machine, one 3.X, which is being called as the default program for .py files, and one 2.X, which is being called when you explicitly call python.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! so true, my mac come with python 2.7.2 and I installed 3.3 .... I guess i should delete one?
@FishOnTray It's perfectly valid to have 2 installs on a machine, just make sure you know how they are configured and which gets run when.
0

For question one: Are you setting the right python interpreter path in the first line of your script starting with #!?

On my machine (Linux) that would be for example:

#!/usr/bin/python

4 Comments

@Thomas: Thanks ;) Does that also work for @Fish? It seems he's using a mac.
@das_weezul A Mac with OSX is just a Unix machine for twice the price.
@gnibbler@sr2222: So true XD
I have a mac. Unfortunately it didn't work for me. the only thing works for me so far is #!/usr/local/bin/python3.3 -tt, but i do have python in /usr/bin/python. may due to i have 2 copy of python though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.