Issue
I'm working on a little side project and it's my first time using Flask. I'm working with a virtual environment and therefore I have a shebang at the beginning of my script, that looks like this
#!flask/bin/python
When I try to execute my script from the command line, I get the following error:
-bash: ./run.py: flask/bin/python^M: bad interpreter: No such file or directory
I know that this means that the python interpreter couldn't be found, but if I navigate into flask/bin i can see the interpreter inside. Those are all the files inside of flask/bin
activate
activate.csh
activate.fish
activate_this.py
easy_install
easy_install-2.7
pip
pip2
pip2.7
python
python-config
python2 -> python
python2.7 -> python
wheel
I tried to delete my virtual environment directory and create it again, but this didn't help.
Why does my shebang not work in this case?
Solution
Did you write the script in a Windows environment and then move it over to a UNIX environment? Because the line endings are different, files written in one environment will not automatically work on the other. See here for more info.
To resolve this, try using dos2unix, or if you're using something like Notepad++ on Windows, there are often options to save the file in a Windows format.
Answered By - Mark Answer Checked By - Senaida (WPSolving Volunteer)