Forums

flummoxed

Hi , i just set up a freebie account on PA but the system does not seem to function as I expected. See very simple first script below... it fails to return correct sys version and also fails with error. I'm pretty sure this should work ...but have been wrong before ;-)

1
2
3
4
5
6
7
#!/usr/bin/env/python3.4

# have we chmod +x?
import sys
print (sys.version) # hoping your going to reflect the shebang
x = input('Please enter something: ')
print ("you input:" + (x))

output is:

2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2]
Please enter something: d
Traceback (most recent call last):
  File "myscript.py", line 6, in <module>
    x = input('Please enter something: ')
  File "<string>", line 1, in <module>
NameError: name 'd' is not defined

It's a tiny little thing -- the hashbang should be

1
#!/usr/bin/env python3.4

(note the space, and only three forward-slashes)

Thanks for attention, updated the shebang but we could have missed something , our simple sys.py script :

1
2
3
4
#!/usr/bin/env python3.4

import sys
print(sys.version)

Our resulting output:

> 08:33 ~/Dad $ python sys.py
> 2.7.6 (default, Mar 22 2014, 22:59:56)  [GCC 4.8.2]

Hi there,

The hashbang will now work for when you hit the "Save & Run" button.

If you're in a Bash console, then python means python2.7, so if you run python sys.py, it's always going to open the script withg python2.7, no matter what it says in the hashbang. If you want the shell to obey the hashbang, you can do:

chmod +x sys.py
./sys.py

Or just

python3.4 sys.py

ah thanks for your help Harry ! There is another option, we made an alias in the .bashrc: alias python ="python3.4"