Home>

I want to execute Python of Anaconda3 from Microsoft Visual Studio Code, but I can execute it without any problem immediately after opening the workspace, but from the second time onward

C: /Local/Anaconda3/python.exe c: /Work/Test/excel_read.py
File "", line 1
C: /Local/Anaconda3/python.exe c: /Work/Test/excel_read.py
^^
SyntaxError: invalid syntax

Will stop with an error.

Once I close the VC and restart it, it works fine again, but this is repeated.

Here's what I've done so far:

  1. Installation of Anaconda (Don't check to pass PATH automatically, check to use default Python)
    Location,
    C: \ Local \ Anaconda3
    Designated as.

  2. Install Visual Code (I didn't know the automatic PATH, so leave the default checked)
    Only Japanese localization and Python extensions are installed.
    From Preferences to Python.pythonpath
    C:/Local/Anaconda3/python
    In Python.condapath
    C:/Local/Anaconda3/Scripts /
    I put in.
    I (intentionally) put the same settings for both the user and the workspace, respectively.
    * You can use the base environment instead of the Anaconda virtual environment.
    * It is okay not to debug with breakpoints.

Each version
Windows 10
Visual Code 1.52.1
Anaconda Navigator 1.9.12
is.

  • Answer # 1

    As a result of trial and error with the advice of Mr. yakitorii, I found that I was in the interactive mode (interactive mode) without noticing it myself.
    When in interactive mode, the prompt on the panel screen
    '>>>>
    It seems to be. (It was)
    If you press the execute button on the upper right in this state, an error will occur.

    After clicking on the panel screen
    Ctrl + Z
    So I was able to escape the interactive mode.

    By the way, when entering interactive mode, it seems to select [Python: Start REPL] etc. in the command palette.
    Once I was able to escape, the phenomenon disappeared as long as I touched it for a while.
    Thank you very much.