Forums

pythonanywhere text editor

when using the pythonanywhere text editor, how do you set the default version of python it uses when you run the program ">>>Run this file"

it defaults to

sys.version '3.4.3 (default, Oct 14 2015, 20:28:29) \n[GCC 4.8.4]'

i need to test with 2.7

Hi

You can use the "shebang" line at the top of the python program to select the python version.

For instance:

1
2
3
#!/usr/bin/env python
import sys
print (sys.version)

This will print:

`2.7.6 (default, Jun 22 2015...)

If you change that to:

1
2
3
#!/usr/bin/env python3
import sys
print (sys.version)

(Note the python3 <--- this "3" is important)

You will get this:

3.4.3 (default, Oct 14, 2015...)

...in other words, the environment chosen on that line selects the python version.

I believe if you write a short note to support they can set the default version, but the shebang method is pretty easy.

And yes, "shebang" is a silly name for this whole idea, I agree. :-)

Best wishes,

-greg

geez , I feel so stupid lol

I have been bobbing back and forth between python on windows7 (no /usr/bin ) and ubuntu

,Brand new to pythonanywhere and just tried something trivial to print out the python version the way I would do it on windows . thanks.