4

Here's the problem, after installing Python (3.6, 3.7, 3.8) on Microsoft Windows when you invoke it, it opens in a new window. enter image description here This question has been raised before, and replies talk about modifying the code to pause the output or keep the program running so it doesn't close the window. I can not modify every python package ever made for windows compatability.

My problem is that this is not how Python works on *nix platforms. Surely there must be a way to get python to execute within a command prompt ?

My immediate issue is that I loose the console output on so many python programs. From Jupyter Notebook to AWS GRC (remote-codecommit).

-=-=-=-=-= ANSWER =-=-=-=-=-

After much frustration, it turns out the problem was related to account privileges.

The behaviour above occurred when a user with elevated rights executed Python.

When I log out and run with another user that is a local admin, it now behaves normally.

I cant tell you the exact difference between elevated rights and local admin, but there is something in the permissioning that effects how Python is run on Windows.

Community
  • 1
  • 1
Exie
  • 466
  • 5
  • 16
  • Lookie here: https://stackoverflow.com/questions/9705982/ – Marichyasana Apr 27 '20 at 09:10
  • Thanks for the link, it looks like the same issue, but the solution isnt clear to me. I think the best solution in my case is to talk to my employer about alternative environments as I have no confidence in Python on Windows, even if the core binary runs, its clearly not a mature language on this platform. Just my opinion. – Exie Apr 27 '20 at 10:40
  • That is not normal behavior. Run `where.exe python`. You may have a "python.bat" in `PATH` that's running python.exe via `start`. By default, CMD's `start` command uses a process creation flag that tells the program (e.g. python.exe) to allocate a new console. – Eryk Sun Apr 27 '20 at 18:17
  • Also, generally the py.exe launcher is preferred on Windows. It supports a command line option "-X[.Y][-32|-64]" to select from installed interpreters, and it also supports shebangs in scripts, including virtual support for Unix shebangs such as "#!/usr/bin/python3". The launcher avoids the complexity of managing multiple interpreters `PATH`. It's installed for all users by default. – Eryk Sun Apr 27 '20 at 18:18
  • @ErykSun When you say its not normal, you are right, I just did a fresh install of Python 3.7.7 on another Windows laptop and it works as expected. So leads me to believe my work had done something to this laptop causing it to open in a new window.It's probably part of the Appsense or Veramine rubbish. I'll follow up with them, its obviously them and not the Python language. – Exie Apr 27 '20 at 22:49

2 Answers2

2

This happened to me when the current directory of the terminal didn't exist (was deleted/renamed after the terminal was started).

Solution: cd to some directory.

lapis
  • 6,872
  • 4
  • 35
  • 40
0

Find you python folder and select python.exe and create a shortcut for it. Example Image There's probably a better way, but this is a simple workaround.