macos – env: pythonr: No such file or directory

macos – env: pythonr: No such file or directory

Open the file in vim or vi, and administer the following command:

:set ff=unix

Save and exit:




ff stands for file format, and can accept the values of unix (n), dos (rn) and mac (r) (only meant to be used on pre-intel macs, on modern macs use unix).

To read more about the ff command:

:help ff

:wq stands for Write and Quit, a faster equivalent is Shift+zz (i.e. hold down Shift then press z twice).

Both commands must be used in command mode.

Usage on multiple files

It is not necessary to actually open the file in vim. The modification can be made directly from the command line:

 vi +:wq ++ff=unix

To process multiple *.py files (in bash):

for file in *.py ; do
    vi +:w ++ff=unix +:q ${file}

offtopic: if by chance you are stuck in vim and need to exit, here are some easy ways.

Removing the BOM mark

Sometimes even after setting unix line endings you might still get an error running the file, especially if the file is executable and has a shebang. The script might have a BOM marker (such as 0xEFBBBF or other) which makes the shebang invalid and causes the shell to complain. In these cases python will work fine (since python can handle the BOM) but ./ will fail even with the execution bit set because your shell (sh, bash, zsh, etc) cant handle the BOM mark. (Its usually windows editors such as Notepad which create files with a BOM mark.)

The BOM can be removed by opening the file in vim and administering the following command:

:set nobomb

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(br, b))

macos – env: pythonr: No such file or directory

You can convert the line ending into *nix-friendly ones with

dos2unix beak

Leave a Reply

Your email address will not be published. Required fields are marked *