0

I've written a couple of scripts that I want to run automatically on my computer, so I've added the line #! Applications/anaconda/bin/python to the beginning of each script to made it executable. Oddly enough, one of the programs worked perfectly after adding that line and then running chmod +x \path\to\program.py in the terminal. But for the second program I followed the same process but when I try and run the script from the terminal using \path\to\program.py I get an error which reads: Applications/anaconda/bin/python^M: bad interpreter: No such file or directory. I understand that this means that I have a carriage return on the end of the line that's throwing it off, but I don't understand how to get rid of it. Here are the snippets from my two scripts, this one works:

#! /Applications/anaconda/bin/python


import time
from selenium import webdriver
import easygui
.
.
.

And this one doesn't:

#! Applications/anaconda/bin/python


from datetime import datetime
import calendar
.
.
.
jbones
  • 36
  • 1
  • 5

3 Answers3

0

After doing some more digging. I found that the problem was caused because I had edited the script using both a windows computer and a mac. All that was needed to fix the problem was to copy and paste the code to a new .py file and then it worked like a charm. There are also more technical work arounds here: PyCharm. /usr/bin/python^M: bad interpreter

Community
  • 1
  • 1
jbones
  • 36
  • 1
  • 5
0

Your second script is missing a "/" at the beginning.

This is, replace #! Applications/anaconda/bin/python with #! /Applications/anaconda/bin/python.

antonimmo
  • 393
  • 4
  • 8
0

You should try opening your file using vim and run in command mode

:set fileformat=unix