Making `#!/usr/bin/env python` work on Windows

I use Bash on Windows, provided by MSYS.

I tried to run a Python file with a shebang of #!/usr/bin/env python, but I get this error message:

/usr/bin/env: python: No such file or directory

What can I do to make this work?

I know I can launch the Python file by suffixing it with python, but I want it to work without the suffix too.


Solution 1:

Use the proper path where Python is installed instead, for example:

#!c:/Python/python.exe

If you have Unix-like path support on your system (I'm not familiar with MSYS), you can always enter the path to your python executable, i.e. the output of which python.

Solution 2:

You might be interested in a Python Launcher For Windows

Solution 3:

I turned out to be a mismatch between Virtualenv's activate.sh file and MSYSGIT. It was never intended to work on Windows.