close

[Solved] syntax error when using command line in python

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error syntax error when using command line in python in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How syntax error when using command line in python Error Occurs?

Today I get the following error syntax error when using command line in python in python.

How To Solve syntax error when using command line in python Error ?

  1. How To Solve syntax error when using command line in python Error ?

    To Solve syntax error when using command line in python Error If you have correct variables already set; then you are calling the file inside the python interpreter.

  2. syntax error when using command line in python

    To Solve syntax error when using command line in python Error If you have correct variables already set; then you are calling the file inside the python interpreter.

Solution 1

I faced a similar problem, on my Windows computer, please do check that you have set the Environment Variables correctly.

To check that Environment variable is set correctly:

  1. Open cmd.exe
  2. Type Python and press return
  3. (a) If it outputs the version of python then the environment variables are set correctly.(b) If it outputs “no such program or file name” then your environment variable are not set correctly.

To set environment variable:

  1. goto Computer-> System Properties-> Advanced System Settings -> Set Environment Variables
  2. Goto path in the system variables; append ;C:\Python27 in the end.

If you have correct variables already set; then you are calling the file inside the python interpreter.

Solution 2

Looks like your problem is that you are trying to run python test.py from within the Python interpreter, which is why you’re seeing that traceback.

Make sure you’re out of the interpreter, then run the python test.py command from bash or command prompt or whatever.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read