我最近安装了Python和Visual Studio Code。我上完入门课后写了一个基本脚本并在Visual Studio Code中运行它,却发现了Python在我的Visual Studio Code中设置的问题。
问题:
当我启动Visual Studio Code并打开一个Python文件时,终端默认为"C:\Users\my_name\Documents Python"(这是存储我的Python文件的文件夹)。据我所知,在Python中,提示符应该是">>>"。我能运行我的脚本,但不能在终端中运行任何其他Python代码(例如像z = 5这么简单的代码)。如果我输入"Python",就会出现">>>"的提示符,但无法再运行我的脚本。
我认为这是安装问题,所以我卸载并重新安装了Python和Visual,但问题仍然存在。
我尝试将程序安装路径下的Python文件路径添加到Windows环境中的系统设置中,也在重新安装Python时点击了"添加到Path",但这些解决方案似乎都没有起作用。
当基本的Python代码(例如z=5)无法正常工作,但脚本可以正常运行时,我会得到以下错误消息:
以下是我切换到Python并尝试运行脚本后收到的错误信息。
我认为这是安装问题,所以我卸载并重新安装了Python和Visual,但问题仍然存在。
我尝试将程序安装路径下的Python文件路径添加到Windows环境中的系统设置中,也在重新安装Python时点击了"添加到Path",但这些解决方案似乎都没有起作用。
当基本的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交互模式)时,您无法执行z = 5
,因为它是未知命令。当您尝试在cmd
中运行它时,您将收到相同的错误。您检查了我分享的链接吗? - buran