skip to Main Content

Beginner here. I’ve just learned the basics of python using VS. I don’t know why I get a syntax error in the VSCode text file but not on the terminal for the command.
Any assistance helping me understand would be great, thank you.
screenshot of vscode

Tried to install boto3 with pip.

2

Answers


  1. You cannot run shell commands from a python script.

    This is the right way to do it. You can also use the subprocess module to do it.

    import os
    
    # In Linux
    os.system("python3 -m pip install boto3")
    
    # In Windows
    os.system("py -m pip install boto3")
    

    Although, it’s not recommended installing packages inside your code.

    You can use a requirements.txt file. Then you just need to run this command once in your terminal:

    pip install -r requirements.txt
    
    Login or Signup to reply.
  2. py -m pip install boto3

    Obviously, this does not conform to python syntax.

    Usually we call it a command line.

    We run it in the shell instead of python file.

    Python files will be compiled and then run. This command line statement will not be compiled (As the wavy line in the file reminds, this is an error code). You can further learn Python syntax to learn more about this problem.

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