On 14Dec2012 02:45, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: | I understand this is not exactly a Python question, but it may be of | interest to other Python programmers, so I'm asking it here instead of a | more generic Linux group. | | I have a Centos system which uses Python 2.4 as the system Python, so I | set an alias for my personal use: | | [steve@ando ~]$ which python | alias python='python2.7' | /usr/local/bin/python2.7 | | | When I call "python some_script.py" from the command line, it runs under | Python 2.7 as I expected. So I give the script a hash-bang line: | | #!/usr/bin/env python | | and run the script directly, but instead of getting Python 2.7, it runs | under Python 2.4 and gives me system errors. | | When I run env directly, it ignores my alias: | | steve@ando ~]$ /usr/bin/env python -V | Python 2.4.3 | | | What am I doing wrong?
You're assuming aliases are exported. They are not. (I've seen ksh present exportable aliases, but IMO it is a bad idea anyway.) You're (slightly) better off putting a python symlink in /usr/local/bin, but that may break arbitrary other things (as, indeed, would your #! incantation were it effective). Also a bad idea though. Regarding aliases, I would make a "py27" alias for my personal typing convenience perhaps, but _not_ try to make the command "python" run anything but the system default python (24, as you say). When I need a particular minimum revision of python I use one of my "py25+", "py26+", "py27+", "py30+" etc wrapper scripts. Code for "py25+" here: https://bitbucket.org/cameron_simpson/css/src/tip/bin/py25+ This has the advantages of not conflicting with a system name like "python" and also is usable with your #! incantation, which requires an executable file after "env". Cheers, -- Carpe Datum - John Sloan <jsl...@ncar.ucar.edu> -- http://mail.python.org/mailman/listinfo/python-list