简体   繁体   中英

Running python script in command prompt: syntax error unexpected character after line continuation character

I'm new to Python and have been trying to run a Python script through the cmd terminal (after invoking Python 3.6 in the Anaconda 4.3 distribution). I've looked through various forums which have outlined how to do this. I tried entering the following into the command prompt:

C:\Users\myname\Anaconda3\python.exe C:\Users\myname\Desktop\test.py

However, I get the error "unexpected character after line continuation character". I got the same error when I tried to enter both pathnames separately as well. The reason I want to use the Anaconda distribution is because it has tensorflow installed on it. Thanks!

Check if your file path is spelled properly, and make sure to put double quotes "" around any whitespace.

Try putting the filename in quotation marks and see if that works.

If not, and you've installed anaconda, then you should be able to just type python "C:\\Users\\myname\\Desktop\\test.py" . If python throws you the error then you need to check your python code. If the command prompt throws the error then check out how to add Anaconda's python to your environment variables.

I think you're missing a basic thing here as @user23571122 tried to mention above.

Try this:

  • open CMD.

  • run C:\\Users\\myname\\Anaconda3\\python.exe C:\\Users\\myname\\Desktop\\test.py

    (if there are whitespaces in your user name, then make sure you enclose both the paths in double quotes). Like this - "path\\to\\python.exe" "path\\to\\file.py"

  • and see if it works?

Do NOT invoke python in CMD. Just run the command right after opening CMD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM