1

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!

himi64
  • 1,069
  • 3
  • 12
  • 23
  • 1
    "trying to run a Python script through the cmd terminal (after invoking Python 3.6 in the Anaconda 4.3 distribution)" - no, do not pre-invoke Python. Once you do that, you are now trying to issue shell commands to Python instead of to the shell. – user2357112 Mar 28 '17 at 21:03
  • [Verify](https://conda.io/docs/using/using.html#verify-that-conda-is-installed-check-current-conda-version) the conda install with `conda --version` – brennan Mar 28 '17 at 21:09

2 Answers2

0

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.

Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43
  • Adding quotes returned the syntax error: 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape. Does this mean there is an error in the python code line 2-3? – himi64 Mar 28 '17 at 22:45
  • Ah, so now try `python r"C:\Users\myname\Desktop\test.py"`, as python may be interpreting the `\U` as the start of a unicode escape character. See [here](http://stackoverflow.com/questions/1347791/unicode-error-unicodeescape-codec-cant-decode-bytes-cannot-open-text-file). – Ari Cooper-Davis Mar 29 '17 at 07:38
  • pretty sure the unicode error is only reported by the python interpreter, not the windows commands processor. The issue seems to be that they are invoking `python` before running the command, so they're probably working with an interactive python shell instead of command processor of windows (as indicated by `after invoking python3.6` in the question) – P S Solanki Apr 04 '21 at 13:12
0

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

P S Solanki
  • 1,033
  • 2
  • 11
  • 26