0

I try to run a powershell script from vscode (pressing F5 to execute it), but it fails because somehow the terminal concatenates the python path and python debug launcer along with the powershell path. How do I solve so that when running a Python scripts it takes the python path, and when running powershell it automatically runs powershell?

When running (F5) the powershell script from vscode the following path is interpreted by the terminal:

PS C:\Users\luuk\Desktop\Scripts\Archive\Archive>  & 'C:\Users\luuk\AppData\Local\Programs\Python\Python38\python.exe' 'c:\Users\luuk\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\lib\python\debugpy\launcher' '60329' '--' 'c:\Users\luuk\Desktop\Scripts\Archive\Archive\Powershell\StreamingSQLToPBI.ps1'

What do I need to change so vscode automatically detects only the Powershell path?

4
  • Did you install the PS extension? It might be beneficial to remove it and add it back if you did install it previously. Here is Microsoft’s method to getting started with VSCode and PS: learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/… Commented Dec 6, 2020 at 13:46
  • Hi, yes I did but unfortunately I am unable to get it to work. Do I possibly need to create a different git repository for my powershell code? But then the questions remains, because when running a powershell script it automatically concatenates the python path, python debugger path and powershell path - leading to an error. Commented Dec 6, 2020 at 16:10
  • I need to know how to run powershell scripts without the python path, any idea? Commented Dec 6, 2020 at 16:11
  • The run commands and their configurations are explained here: code.visualstudio.com/docs/editor/… I believe that checking out the documentation and looking over your launch.json file would be beneficial. Commented Dec 6, 2020 at 21:54

1 Answer 1

1

Solution: To execute PowerShell script in VSCode, in addition to installing the extension "PowerShell", we need to open the terminal "PowerShell Integrated Console": (F1, PowerShell: Restart Current Session), then select the code, and click F8 to execute the code in this terminal.

enter image description here

The reason for these paths is that in VSCode, when we click F5 to debug the file, VSCode is executed in the "Python Debug Console" by default. It will specify the Python interpreter used for the terminal and the Python extension used (Python extension provides Python debugging function), the path of the script to be executed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.