1

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

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

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.

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

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.

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.

Ryan
  • 1,486
  • 4
  • 18
  • 28
  • 1
    `py.exe` isn't a Python interpreter, it's a "launcher" that looks for special shebang (`#!`) comments at the beginning of scripts. See this [documention](https://docs.python.org/3/using/windows.html?#python-launcher-for-windows). Also see the [pylauncher project](https://bitbucket.org/vinay.sajip/pylauncher/overview). – martineau Oct 03 '18 at 00:22
  • @martineau can you write that as an answer to the question? – Ryan Nov 03 '18 at 22:36

2 Answers2

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

martineau
  • 119,623
  • 25
  • 170
  • 301
0

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.

Ryan
  • 1,486
  • 4
  • 18
  • 28