skip to Main Content

I am trying to run a simple "Hello World" script which is named print("hello world!").py by pressing the "play" button in the top-right of the VS Code window.

I’m using Python 3.13.0, macOS 12.6.1 and VS Code 1.94.

The VS Code terminal prints:

dafyddpowell@Dafydds-MBP ~ % cd "/Volumes/SAMSUNG/Python projects"  
dafyddpowell@Dafydds-MBP Python projects % /usr/bin/python3 "/Volumes/SAMSUNG/Python projects/print("Hello world!").py"  
zsh: parse error near `)'  
dafyddpowell@Dafydds-MBP Python projects % 

screen shot of file content

What is wrong?

3

Answers


  1. Use a file name something like "print_hello_world.py".

    Login or Signup to reply.
  2. It seems like VSCode isn’t escaping the file name that contains special characters.

    The simplest way around this would be to use a filename that doesn’t have any special characters like hello_world.py.

    Login or Signup to reply.
  3. If the underlying shell is bash (or equivalent in terms of how the command line is interpreted) then:

    /usr/bin/python3 '/Volumes/SAMSUNG/Python projects/print("Hello world!").py'
    

    Whilst the filename is legal, it’s not very sensible

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search