'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!
Solution 1:[1]
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.
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ari Cooper-Davis |
Solution 2 | P S Solanki |