Absolute paths aren't portable on Unix either, although
# ! /usr/bin/env python2.2
I wouldn't mind if users who need this feature would be required to know where their interpreter lives.
I don't believe any user needs this feature! Not on their own box. Let's be clear about "the problem" (or at least about Logajan's): you want to distribute your Python scripts all over the world. You're targeting Windows, and Unix flavors, and Macs (you hope). Freezing an interpreter into your distro isn't an option, as you have no idea how to even go about finding out how to do that on all the platforms your users run on, and you don't have access to all of them anyway. What then can you do to ensure that your scripts won't break on your users' boxes when they happen to upgrade their own Python installations?
The only way I see that a "#!" line could do a lick of good for you then is if it were a x-platform way to identify version number, and that's all. It would also need to abort with "This app requires Python I.J" if it couldn't find Python I.J on the box. As a matter of fact, it wouldn't do Logajan any good even if Python 2.3 did a perfect job of that, as he only cares about 1.5.2. Going forward, maybe it would do someone some good. I'm skeptical of the cost/benefit ratio, though (James is extreme, IMO).
But I wouldn't mind a registry-based solution either:
# ! python2.2
could mean "find Python 2.2 in the registry".
If it didn't also mean "find Python 2.2" on Linux and Macs, it wouldn't do anything to help the people who are unhappy in James's way.
I believe the PythonWare distro always installs in the same place, so if Fredrik thinks this will be useful, we could provide a hack that looks in certain places on the filesystem if no registry key is found.
Still, I'd prefer to do the simplest thing that could possibly work, which IMO would be just an absolute pathname.
It can't possibly work, except to solve a problem I haven't heard anyone bring up. I expect the simplest thing that could possibly work for James's problem would be to add a pragma "#requires 2.3", and teach Python to complain if its own version doesn't match what the pragma says. It would also need some way to do this in .pyc and .pyo files. But that's not really want James wants either: he wants his scripts to run forever without change, under all Pythons that will ever be released, and on all platforms.