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

42,113

Solution 1

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

Solution 2

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 3

You might be interested in a Python Launcher For Windows

Share:
42,113

Related videos on Youtube

Ram Rachum
Author by

Ram Rachum

Israeli Python developer.

Updated on September 18, 2022

Comments

  • Ram Rachum
    Ram Rachum over 1 year

    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.

  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams over 12 years
    Or you could use env, as the asker is doing.
  • Ram Rachum
    Ram Rachum over 12 years
    I can't change the shebang, it's part of a project which involves other programmers that work on Linux and Mac.
  • HikeMike
    HikeMike over 12 years
    @RamRachum What's the output of which env and which python and type python?
  • phlummox
    phlummox about 2 years
    Hard-coding the path to the interpreter doesn't seem like a very portable solution. I'd like this answer better if it considered whether there are more portable options (there may not be), and what the tradeoffs are.