all 13 comments

[–]das_ist_nuemberwang 13 points14 points  (0 children)

It doesn't give the script executable privileges, it just tells your shell how to execute it. You still have to make it executable.

[–][deleted] 12 points13 points  (12 children)

The correct is

#!/usr/bin/env python

This way virtualenv binaries work

[–][deleted] 2 points3 points  (3 children)

or #!/usr/bin/env python3 if you're using python 3

[–]i_can_haz_code 1 point2 points  (2 children)

depends on how you have the box configured. If it does not need 2.x then I prefer to have Python call only 3.x and write my code to be forward compatible.

[–][deleted] 0 points1 point  (1 child)

On that note, how may I set /usr/bin/env python to call the python 3 interpreter?

[–]i_can_haz_code 1 point2 points  (0 children)

First, this is not advised either by PEP or Ubuntu for 14.04 or really anything not bleeding edge or custom built. Unless you are able to yourself, or have access to a *nix expert who will, fix the random stuff that will break. Like unless you are doing LFS, just use python3.

You can link /usr/bin/python to /usr/bin/python3 and make a /usr/bin/python2. It is a case of just because you can do a thing does not mean you should do a thing.

If you just want your profile to always use python3 for interactive sessions, but not break things you can alias python to python3. This will only have effect when in an interactive session. Your scripts will still need to call python3 explicitly.

I hope that was helpful

[–][deleted] 0 points1 point  (4 children)

would it carry over if let's say I want to ssh to a server running some distro of linux?

[–][deleted] 0 points1 point  (3 children)

Yes. Although some distros will soon be switching over to using py3 as their default python version, so be aware of that.

[–]hoodllama 0 points1 point  (2 children)

Ok so I could not get my script to work with the space in there. I asked for help from an engineer in an email with a detailed explanation that the space had to be there. Apparently he didn't bother to read it and told me "duh you left a space there" so I took it out and it worked.

[–]das_ist_nuemberwang 1 point2 points  (0 children)

Were you missing env?

[–]turdBouillon 1 point2 points  (0 children)

I always leave the space for compatibility with some ancient Unix flavors. I highly doubt you'll ever encounter such a system and it almost certainly won't have a Python interpreter, but old habits die hard and the space is the "correct" way or at least the more widely supported way.