1

I am running a python script from the IDE and it works well, however when calling it from the git-bash terminal the following errors showed.

./main.py: line 2: import: command not found
./main.py: line 3: import: command not found
./main.py: line 5: syntax error near unexpected token `'I am in main 1''
./main.py: line 5: `print('I am in main 1')'

In git-bash I run the chmod u+x main.py and chmod +x main.py lines, but it still does not work.

I am using VScode as my IDE with python3.7.9 as the interpreter, I am calling the script from the direction where it is placed in the terminal, and the script that I am testing is the following:

#!/bin/bash
import os
import sys

print('I am in main 1')

I have changed the first line for #!/bin/bash/python and #!/bin/bash/env python3... didn't work. I would appreciate it if someone could tell me what I miss or what I am doing wrong. I am new in git or using the terminal, any tip would be appreciated.

Thanks in advance.

1 Answer 1

3

Not sure if you made the error in typing this question or if it's also like this in your script, but you should have #!/usr/bin/python3 or #!/bin/python3 for your system to know to execute it as a python script.

As it stands, your system is trying to execute it as a shell script with bash, which would explain why the import statements aren't being recognized.

Sign up to request clarification or add additional context in comments.

3 Comments

It returns this: 'bad interpreter: No such file or directory'. The exact path of the interpreter is: 'C:/Users/andre/AppData/Local/Programs/Python/Python37/python.exe'
I'm sorry, I took for granted that you were on a unix-style system because of the filepaths you were trying. For a Windows system you can refer to this question.
No worries, thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.