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
Related videos on Youtube
Comments
-
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 over 12 yearsOr you could use
env
, as the asker is doing. -
Ram Rachum over 12 yearsI can't change the shebang, it's part of a project which involves other programmers that work on Linux and Mac.
-
HikeMike over 12 years@RamRachum What's the output of
which env
andwhich python
andtype python
? -
phlummox about 2 yearsHard-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.