/usr/bin/env: python: No such file or directory

Paul Boddie paul at boddie.net
Wed Dec 19 09:48:57 EST 2001


hamish_lawson at yahoo.co.uk (Hamish Lawson) wrote in message news:<915a998f.0112161542.2ab07235 at posting.google.com>...
> > When trying to run a script, I get the following message:
> > 
> > /usr/bin/env: python: No such file or directory
> 
> Though perhaps not the case here, I'll just mention a problem that is
> worth being aware of when transferring a script from a Windows/DOS
> system to Unix. If the difference in line-ending conventions hasn't
> been taken care of (such as by using ASCII mode during FTP transfer),
> then the spurious ^M in the script's #! line can trip up the shell or
> the env command, since it will be trying to run the program python^M.

This may well be the case, in fact. One solution is to write a short
Python script to replace the DOS line endings with the native
equivalent. Something like this, perhaps:

  # Warning! Untested! Try it on something you've already backed up!
  s = open(filename, "rb").read()
  # NOTE: Python 2 string methods used - import string and use
  # NOTE: string.replace with earlier releases of Python.
  s = s.replace("\r\n", "\n")
  open(filename, "w").write(s)

Yes, I know it could have been done on one line (or using 'sed')! :-)

Paul



More information about the Python-list mailing list