neolee / wop-community

29 stars 19 forks source link

vscode无法在终端运行python文件 #336

Closed 2269881521 closed 1 year ago

2269881521 commented 1 year ago

在PowerShell的命令行中运行python test.py的命令,会出现以下报错 屏幕截图 2023-10-20 230534 但是点击右上方的运行代码,则是可以正常运行的 屏幕截图 2023-10-20 231355

neolee commented 1 year ago

这个情况恰恰说明你系统里的Python环境存在某些潜在问题,以后可能带来很多麻烦,借此机会彻底理清为上。

在PowerShell命令行中一条一条地执行下面的命令,把每一条的结果贴上来:

Get-Command python
Get-Command python3
Get-Command pip
Get-Command pip3
python -V
python3 -V
pip -V
pip3 -V
2269881521 commented 1 year ago

`PS C:\Users\86173\Code> Get-Command python

CommandType Name Version Source


Application python.exe 0.0.0.0 C:\Users\86173\AppData\Local\Microsoft\WindowsApps\python.exe

PS C:\Users\86173\Code> Get-Command python3

CommandType Name Version Source


Application python3.exe 0.0.0.0 C:\Users\86173\AppData\Local\Microsoft\WindowsApps\python3.exe

PS C:\Users\86173\Code> Get-Command pip

CommandType Name Version Source


Application pip.exe 0.0.0.0 C:\Users\86173\AppData\Local\Programs\Python\Python312\Scripts\pip.exe

PS C:\Users\86173\Code> Get-Command pip3

CommandType Name Version Source


Application pip3.exe 0.0.0.0 C:\Users\86173\AppData\Local\Programs\Python\Python312\Scripts\pip3.exe

PS C:\Users\86173\Code> python -V PS C:\Users\86173\Code> python3 -V PS C:\Users\86173\Code> pip -V pip 23.3 from C:\Users\86173\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12) PS C:\Users\86173\Code> pip3 -V pip 23.3 from C:\Users\86173\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12)`

2269881521 commented 1 year ago

PS C:\Users\86173\Code> python -V PS C:\Users\86173\Code> python3 -V 在执行上述两条指令时会报错 屏幕截图 2023-10-21 144917

neolee commented 1 year ago

前面的输出结果,显示在PowerShell命令行里找不到你安装的Python,这是很大的隐患,建议检查系统PATH变量的设置,必要时重装Python包。

2269881521 commented 1 year ago

https://blog.csdn.net/marwenx/article/details/107118715#:~:text=%E9%A6%96%E5%85%88%E5%8F%AF%E4%BB%A5%E5%B0%86%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E4%B8%AD%E7%9A%84%20C%3AUsersMarvinAppData%20Local%20MicrosoftWindowsApps,%E7%A7%BB%E5%88%B0python%E7%9A%84%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E4%B8%8B%E9%9D%A2%20%E5%B0%B1%E5%83%8F%E8%BF%99%E6%A0%B7%EF%BC%8C%E7%82%B9%E8%BF%99%E4%B8%AA%E5%BE%AE%E8%BD%AF%E7%9A%84%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%EF%BC%8C%E7%84%B6%E5%90%8E%E7%82%B9%E4%B8%8B%E7%A7%BB%EF%BC%8C%E7%A7%BB%E5%88%B0python%E8%B7%AF%E5%BE%84%E7%9A%84%E5%90%8E%E9%9D%A2%E5%B0%B1%E5%8F%AF%E4%BB%A5%E4%BA%86%E3%80%82%20%E7%84%B6%E5%90%8E%E6%89%93%E5%BC%80power%20shell%E5%86%8D%E8%BE%93%E5%85%A5python%E6%88%96%E8%80%85python3%E8%AF%95%E8%AF%95%E3%80%82 根据方法一进行了操作,问题已解决