首页 > 解决方案 > Python:在vscode中按shift + enter后无法运行代码

问题描述

我在 conda 环境中的 vscode 中运行 python 3.7。.ipynb我确实在 jupyter notebook和普通 python之间切换.py

我面临的问题发生在按shift enter常规.py文件后。发生的情况是解释器将 a&作为 python 路径的第一个字符,这导致Synthax Error.

当我不小心按下shift enter运行时,.py file我必须重新启动 vscode 才能让终端再次工作。

此路径由运行.py文件的终端显示,没有问题。


PS C:\Users\luuk\Desktop\Scripts\Archive\Archive> conda activate base
PS C:\Users\luuk\Desktop\Scripts\Archive\Archive> & C:/Users/luuk/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/luuk/Desktop/Scripts/Archive/Archive/Python/Pipelines/azdl_adb_chunks.py"

这是按下文件后显示shift enter的内容.py

Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment

Type "help", "copyright", "credits" or "license" for more information.

>>> & C:/Users/luuk/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/luuk/Desktop/Scripts/Archive/Archive/Python/Pipelines/azdl_adb_chunks.py"
  File "<stdin>", line 1
    & C:/Users/luuk/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/luuk/Desktop/Scripts/Archive/Archive/Python/Pipelines/azdl_adb_chunks.py"
    ^
SyntaxError: invalid syntax

尚未在堆栈上发现此问题,因此非常欢迎您提出建议!

标签: pythonvisual-studio-code

解决方案


推荐阅读