Ubuntu Version:
Ubuntu 22.04.5 LTS
Desktop Environment (if applicable):
GNOME v42.9
Problem Description:
I’ve been learning Python, and up until yesterday, I could run my scripts by putting the shebang #!/usr/bin/env python3
in the first line. However, as of this morning, that no longer works, and I can’t figure out why.
As far as I’m aware, I didn’t change any environment variables, and there were no system updates last night. The only way I can get the scripts to run now is by running python3 script.py
in the terminal. I have some screenshots of the terminal below with captions.
Did I accidentally change an environment variable without realizing it? How do I get the shebangs to work again?
Relevant System Information:
Python v3.10.12 installed.
Screenshots or Error Messages:
The system recognizes python is installed.
user@host:[path]$ which python3
/usr/bin/python3
Running the script with the shebang “#!/usr/bin/env python3”…
user@host:[path]$ ./server.py
/usr/bin/env: ‘python3\r’: No such file or directory
Running the script with the shebang “#!/usr/bin/python3”…
user@host:[path]$ ./server.py
bash: ./server.py: /usr/bin/python3^M: bad interpreter: No such file or directory
Running it as an argument for the interpreter…
user@host:[path]$ python3 server.py
Listening for connections on port 4000
user@host:[path]$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
What I’ve Tried:
I’ve tried using #!/usr/bin/env python3
and #!/usr/binpython3
, but neither work. The only way to run any Python script now is by passing the script as an argument into the Python interpreter with python3 script.py
.
Also, unrelated, but if someone could help me understand this, I’d really appreciate it. It’s been several months since I used the Ubuntu Forums, and this new “Discourse” thing is really confusing me. I signed in with my UbuntuOne username, but it made me create a new account, anyway. So, none of my history from Ubuntu Forums is here. Am I going to lose all the past threads and PMs that I had in the Ubuntu Forums? I used to refer to those when a problem I’d solved came up again. Do I still use my UbuntuOne login here, or do I have to use the new one?