0

I have two python scripts in the same folder that I am trying to run in a Github Codespace.

I used which python3 and my output is /opt/python/<python version>/bin/python3. I am using the symlink stable instead of <python version> to make my scripts a bit more installation agnostic.

When I add the she-bang #!/opt/python/stable/bin/python3 to one of my files, everything is executed as expected, but when I use the same she-bang on a different file in the same directory, it doesn't work and I get the following error:

bad interpreter: no such file or directory

Any ideas? I can't seem to find much about this behavior online.

taylorSeries
  • 505
  • 2
  • 6
  • 18
John Ingram
  • 164
  • 1
  • 12
  • 3
    Check for DOS newlines. A file saved in Windows format has a carriage return at the end of each line but the last, and you may have a `python3` executable, but you probably don't have a `python3$'\r'` executable. – Charles Duffy Sep 13 '22 at 20:36
  • 1
    Use `dos2unix filename.py` to fix it if that's the problem. – Barmar Sep 13 '22 at 20:38
  • One thing you can do to validate that is to compare `head -n1 working.py | xxd` and `head -n1 broken.py | xxd`. If you have an extra byte of output in the broken case (ending with `0d 0a` instead of just `0a`), there's your problem. – Charles Duffy Sep 13 '22 at 20:53
  • Thanks, y'all were correct `dos2unix` fixed the problem. – John Ingram Sep 13 '22 at 21:03
  • Great. I'm closing this as a duplicate of some other questions about the same problem -- it's not python in the shebang in the duplicates, but the cause is the same and the solution the same regardless. – Charles Duffy Sep 13 '22 at 21:19

0 Answers0