1

While running a file entitled shuf.py in the linux environment, I run into this following error

./shuf.py -e cats and dogs
-bash: ./shuf.py: /usr/bin/python^M: bad interpreter: No such file or directory

But when i do the same thing as below, it works fine python shuf.py -e cats and dogs

I appended my PATH so that it is correct and the first line of my code is #!/usr/bin/python

I'm not sure what the problem is?

4
  • 4
    Looks like your script has the wrong line endings (saved on a windows machine?). You can use tr to translate, e.g. tr -d '\r' < shuf.py > shuf-new.py Commented Apr 28, 2018 at 18:38
  • 1
    use the dos2unix command line utility to convert your script Commented Apr 28, 2018 at 18:38
  • The tr command makes it work! But i also have to make sure that the code works with Python3, and when i change the first line to #!/usr/bin/python, I get the error that -bash: ./shuf-new.py: /usr/bin/python3: bad interpreter: No such file or directory Commented Apr 28, 2018 at 18:48
  • 1
    Possible duplicate of Python code from Windows to Linux, How to change end-of-line conventions?, Python script gives : No such file or directory, etc Commented Apr 28, 2018 at 20:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.