![](/img/trans.png)
[英]python shell gives syntax error when running a print() ,however the same code executes in jupytr notebook
[英]Running python in terminal in vs code gives me a syntax error, however, manually selecting the code and running it does not give me the syntax error
当我单击“在终端中运行 python 文件”时,出现以下错误:
>>> & C:/Users/HP/python/anaconda/python.exe "d:/python/vscode/python course/3. pandas/dataframes 231021.py"
File "<stdin>", line 1
& C:/Users/HP/python/anaconda/python.exe "d:/python/vscode/python course/3. pandas/dataframes 231021.py"
^
SyntaxError: invalid syntax
但是,当我手动 select 代码行并按 shift enter 运行选定的代码行时,它在 vs 代码中运行完美。
Go 到终端,在右侧你会看到一个名为 powershell 的停靠面板,当你在它上面输入 hover 时,它会显示一个垃圾箱 ui(图像像垃圾箱)。 如果您有多个选项卡,请单击垃圾箱关闭所有选项卡。 这样做,终端将关闭,然后只需再次运行代码,问题就应该解决了!(摆弄了 3 天后对我有用)
注意:终端右侧面板上的所有内容都应关闭。 如果终端没有关闭,请尝试关闭 vs code 并再次打开并执行相同的操作。 我的也在停靠面板中打开了 python。
我会建议在命令提示符和 VS Code 中检查 python 版本。 我怀疑他们指向不同的版本。 在这种情况下,您使用 venv 创建虚拟环境并在两种情况下共享相同的环境,以便获得一致的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.