Cannot pass an argument to python with "#!/usr/bin/env python"

arguments, python, shebang

Solution

It is better to use environment variable to enable this. See python doc : http://docs.python.org/2/using/cmdline.html

for your case:

export PYTHONUNBUFFERED=1
script.py

Problem

I needed to have a directly executable python script, so i started the file with `#!/usr/bin/env python`. However, I also need unbuffered output, so i tried `#!/usr/bin/env python -u`, but that fails with `python -u: no such file or directory`. I found out that `#/usr/bin/python -u` works, but I need it to get the `python` in `PATH` to support virtual `env` environments. What are my options?

Original source

Related problems