10

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.

migrated from stackoverflow.com Jan 14 '12 at 23:56

This question came from our site for professional and enthusiast programmers.

7

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.

  • 2
    Or you could use env, as the asker is doing. – Ignacio Vazquez-Abrams Jan 15 '12 at 0:07
  • I can't change the shebang, it's part of a project which involves other programmers that work on Linux and Mac. – Ram Rachum Jan 16 '12 at 11:25
  • @RamRachum What's the output of which env and which python and type python? – Daniel Beck Jan 16 '12 at 11:33
3

You might be interested in a Python Launcher For Windows

0

What happens when you run (from the shell):

$ /usr/bin/env python

..?

If it starts an interactive python session, then python can be found. (You can also simply run: type python). If it prints "no such file or directory", then python isn't being found in your PATH. See if the following can be tweaked to fix the problem (spaces in the path/to/python will probably cause issues):

$ export PATH=$PATH:/path/to/python
$ /usr/bin/env python
0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.