Niklas R Niklas R - 1 year ago 135
Python Question

env: python\r: No such file or directory

My Python script

contains the following shebang:

#!/usr/bin/env python

When I run the script
$ ./beak
, I get

env: python\r: No such file or directory

I previously pulled this script from a repository. What could be the reason for this?

Answer Source

The script contains CR characters. The shell interprets these CR characters as arguments.

Solution: Remove the CR characters from the script using the following script.

with open('beak', 'rb+') as f:
    content =
    f.write(content.replace(b'\r', b''))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download