【发布时间】:2020-01-02 23:48:59
【问题描述】:
我最近安装了 Python 和 Visual Studio Code。上完介绍课后,我编写了一个基本脚本并在 Visual Studio Code 中运行它。那时我注意到在我的 Visual Studio 代码中设置 Python 的方式存在问题。 问题: 当我启动 Visual Studio Code 并打开一个 python 文件时,终端默认为“C:\Users\my_name\Documents Python”(这是我的 python 文件存储的文件夹)。据我了解,当您使用 Python 时,提示符应该是“>>>”。我能够运行我的脚本,但我无法在终端中运行任何其他 Python 代码(即像 z = 5 这样简单的代码)。如果我输入“Python”,我会收到“>>>”的提示,但无法再运行我的脚本。
我认为这是一个安装问题,所以我卸载并重新安装了 Python 和 Visual,但问题仍然存在。
我尝试在系统设置下将程序安装位置的 Python 文件路径添加到 Windows 环境中,并在重新安装 Python 时单击“添加到路径”,但这些解决方案似乎都不起作用。
当基本 python 代码(即 z=5)似乎不起作用但脚本运行良好时,我收到以下错误消息:
PS C:\Users\my_name\Documents\Python 2> z=5
z=5 : The term 'z=5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ z=5
+ ~~~
+ CategoryInfo : ObjectNotFound: (z=5:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
以下是我切换到 python 并尝试运行我的脚本后收到的错误消息
PS C:\Users\my_name\Documents\Python 2> python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> & C:/Users/my_name/AppData/Local/Programs/Python/Python37-32/python.exe "c:/Users/my_name/Documents/Python 2/new2.py"
File "<stdin>", line 1
& C:/Users/my_name/AppData/Local/Programs/Python/Python37-32/python.exe "c:/Users/my_name/Documents/Python 2/new2.py"
^
SyntaxError: invalid syntax
>>>
【问题讨论】:
标签: python python-3.x powershell visual-studio-code