Git Bash Error on Windows 10: /c/Python39/Scripts/aws: c:\python39\python.exe^M: bad interpreter: No such file or directory

Sneha Herle
3 min readJun 25, 2021

Does the title seem familiar? If so, then you have landed at the right place. I have struggled with this error for many days and no article helped me in particular. Finally, after multiple trial and errors, I could fix it and would love to share it with you in case you’re stuck too.

Here’s the scenario:

I was working on an AWS SAM project and wanted to deploy my code to the S3 bucket through a bash script which had the deployment commands. Let’s name this script as script.sh.fixed.

Next, I opened Git Bash on my Windows machine and executed the below command in my project directory:

$bash script.sh.fixed

And this weird error came up:

Error message

Solution:

Step1) Open the aws Python file at the path mentioned in the error: C:\Python39\Scripts\aws

It will look like this:

C:\Python39\Scripts\aws

Notice the shebang #!c:\python39\python.exe. This is not being correctly read by Git.

Step2) So, let’s make sure first that Python is working in our Git window:

$python
$python

Now, we are sure that Python is installed correctly but Git is unable to use it for execution through the shebang.

Step3) Next, check whether the PATH environment variable is set correctly for Python:

$which Python
$which Python

Check if the above path is added in the PATH environment variable. If not, then add it there.

Step4) Last step, go back to the aws Python file and change the shebang to #!/usr/bin/env python.

The file should now look as:

C:\Python39\Scripts\aws

Save it and reopen Git Bash and try to execute the shell script, and it will now successfully execute, the reason being we have redirected the shebang to take the path of Python from the environment variable which we had set.

Please note that this error can be due to a lot of reasons and there are many solutions for the same.

Hope this solution helps you!

Happy Coding! :)

--

--

Sneha Herle

I'm a Software Developer with a penchant for coding. My greatest passion is to work on a product which makes lives better and has a positive impact on nature.