Skip to content Skip to sidebar Skip to footer

Why Is Python Broken In Visual Studio 2017?

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 mysc

Solution 1:

This isn't really a proper answer, because I'm not sure about how it relates to the problem you're having with respect to Visual Studio 2017 and PowerShell—but since you asked me to post it as though it was one, I'm doing so.


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

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.

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...

Solution 2:

Visual Studio 2017 uses PowerShell as its shell / execution environment.

The problem is due to some issue in PowerShell adopting the properties of Cygwin's execution environment including the virtual path.

The problem randomly went away. One second, PowerShell is reporting its working directory as /cygdrive/c/folder/to/working/directory and acting exactly like Cygwin Terminal. The next time I ran PowerShell, it functioned correctly, returning this kind of output to pwd:

PS C:\WINDOWS\system32> pwd

Path
---- 
C:\WINDOWS\system32

This problem is a combination of two problems. The first one has to do with py.exe not recognizing Cygwin as an interactive shell, as explained in this answer.

The second has to do with PowerShell adopting Cygwin's execution environment. Not sure how this happens, or why it suddenly stopped happening.

Post a Comment for "Why Is Python Broken In Visual Studio 2017?"