1

I'm starting to learn Linux and I wanted to create myself an python file with simple line of code which is

print("Hello World")

Running the file in terminal gives me this error that I cannot fix which says

Syntax error near unexpected token ` "Hello World!" '

I tried adding \ and / next to parenthesis but it didn't work either. Any ideas?

3
  • Does it change if you execute it via 'python file1.py' command on terminal? Commented Nov 11, 2020 at 16:37
  • 1
    You should run it as python file1.py not using ./ unless you specify the interpreter path in the script. Commented Nov 11, 2020 at 16:38
  • 2
    Which is to say: Your first line should be something like #!/usr/bin/env python; otherwise your shell will assume that the script is a shell script, and run it with a shell instead of with a Python interpreter. Commented Nov 11, 2020 at 16:40

1 Answer 1

4

This error comes from bash, not Python. As if you were to type print("Hello World") in your terminal. Try running the python file as python3 file3.py.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.