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.

link|improve this question

72% accept rate
feedback

migrated from stackoverflow.com Jan 14 at 23:56

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

4 Answers

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.

link|improve this answer
1  
Or you could use env, as the asker is doing. – Ignacio Vazquez-Abrams Jan 15 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 at 11:25
@RamRachum What's the output of which env and which python and type python? – Daniel Beck Jan 16 at 11:33
feedback

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
link|improve this answer
feedback

You might be interested in a Python Launcher For Windows

link|improve this answer
feedback
up vote 0 down vote accepted

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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