Skip to content
Advertisement

Powershell opens new cmd window, when running python script

Recently i re-installed python. Now when i type “.script.py” in powershell, it opens new cmd window, but i wanted to launch in the same window. How to change it? P.S. cmd works fine.

Advertisement

Answer

For Conda / Anaconda, I did the following command to invoke the correct Python executable for the correct environment I was in (executing this command from an Administrator CMD session):

ftype Python.File="%CONDA_PREFIX%python.exe" "%1" %*

Otherwise it won’t recognize the libraries installed for the activated environment.

And also of course:

  • Add .PY to the PATHEXT System variables (from the Environment Variables dialog box of System Properties)
  • Associate .py with Python.File from an Administrator CMD prompt. assoc .py=Python.File

Once this was done, both DOS and Powershell command lines worked as expected.

Advertisement