为什么在Visual Studio 2017中Python损坏了? [英] Why is Python broken in Visual Studio 2017?

查看:186
本文介绍了为什么在Visual Studio 2017中Python损坏了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装Visual Studio 2017之前,我的所有python文件都已在PowerShell,Git Bash和Cygwin Terminal中使用py(或py3)成功运行,但未在CMD.exe或MSYS中运行:

Before installing Visual Studio 2017, all my python files were successfully running using py (or py3) in PowerShell, Git Bash, and Cygwin Terminal, but not CMD.exe or MSYS:

py myscript.py

此可执行文件由Python 3.7安装程序直接安装,我为其配置了路径变量.

This executable was installed directly by the Python 3.7 installer, and I configured the path variables for it.

在安装VS 2017之后,Microsoft将指向VS的py.exe副本py.exe C:\Windows\py.exe的路径插入到系统PATH变量中.直接运行时,此python副本不执行任何操作,并且不会响应exit()命令以终止其线程,而将脚本传递给它时,脚本也不执行任何操作.从字面上看,什么都不起作用,甚至print()语句也没有.

After installing VS 2017, Microsoft inserted the path to their VS-specific copy of py.exe, C:\Windows\py.exe into the system PATH variable. This copy of python does nothing when run directly, and will not respond to exit() command to terminate its thread, and scripts do nothing when passed into it. Literally nothing works, not even print() statements.

在Visual Studio中,打开解决方案资源管理器"窗口并右键单击script.py,然后单击Start without Debugging,没有任何反应.

In Visual Studio, after opening the "Solution Explorer" window and right clicking on script.py and clicking Start without Debugging, nothing happens.

如果单击Start with Debugging,则它将视图更改为调试模式,并运行"程序(显示暂停和停止按钮),但没有显示执行窗口. 输出"面板会自动选择调试",并且那里没有输出.未填充汽车"和本地"面板,表明实际上没有任何运行.

If I click Start with Debugging, then it changes the view to a debugging mode, and "runs" the program (the pause and stop buttons are showing), but no execution window shows up. The Output panel automatically selects "Debug" and there is no output to see there. The "autos" and "locals" panels are not populated, indicating that nothing is actually running.

我不需要解决方法.我知道我可以从PATH中删除该条目,但是官方的Python安装可能与VS 2017不兼容,或者可能缺少集成.我想知道为什么Microsoft的py.exe副本在所有情况下都会失败,以及它们针对此问题的官方修补程序.

I don't want a work-around. I know I could delete this entry from PATH, but the official Python installation may not be compatible with VS 2017 or might lack integrations. I want to know why Microsoft's copy of py.exe fails at everything and what their official fix is for this problem.

推荐答案

这并不是一个正确的答案,因为我不确定它与您在视觉方面所遇到的问题之间的关系Studio 2017和PowerShell –但是由于您要求我将其发布为好像是一个,所以我正在这样做.

Microsoft未安装C:\Windows\py.exe可执行文件,而Python安装程序已安装了该文件.

Microsoft didn't install the C:\Windows\py.exe executable, the Python installer did.

还请注意,它不是Python解释器,而是命令行启动器"实用程序,用于在脚本文件的开头查找特殊的shebang(以#!为前缀)注释.它使Windows上运行Python脚本的工作方式与Linux上类似,并且在系统上安装了多个Python版本(例如2.x和3.x)时会有所帮助.

Also note, it's not a Python interpreter, it's a command-line "launcher" utility that looks for special shebang (#! prefixed) comments at the beginning of script files. It makes running Python scripts on Windows work somewhat like it does on Linux—and helps when you have more than one Python version (such as both 2.x and 3.x) installed on your system.

pylauncher项目中.它起源.

See the following about using Python on Windows in the Python documentation. Also see Vinay Sajip's (the author) version control repository for the pylauncher project which is where it originated.

正如我在序言中所述,我不确定这一切与您的问题有什么关系,但我认为了解事情的正常运行方式可能会帮助您解决问题.

As I said in the preface, I'm not sure how all this relates to your problem, but feel that understanding how things normally work may help you resolve the issue.

希望您发现它很有见地...

Hope you found it insightful...

这篇关于为什么在Visual Studio 2017中Python损坏了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆