Issue
I am using Visual Studio (not Visual Studio Code) for the development of a Python application.
Is there a way to make the Visual Studio's Developer PowerShell auto-activate the virtual environment, as is possible in PyCharm or in VS-Code? Right now, I have to explicitly run the command .\env\Scripts\activate in the Terminal to activate the Virtual Environment.
Solution
I found a key in setting up PowerShell startup arguments.
Go to the Visual Studio 2022 Parameters -> Environment -> Terminal. In "Profiles" window click on PowerShell for developers (Default), then Arguments and follow next steps:
- Add
-ExecutionPolicy RemoteSignedin the very beginning. - Find
-Command "&{ Command1; Command2; ...; CommandN}"syntax and addenv\Scripts\activateas one of the commands (so it looks like-Command "&{ Command1; Command2; ...; env\Scripts\activate}").
Congrats! Now Visual Studio will activate your env every time you create PowerShell console.
NOTE:
-ExecutionPolicy RemoteSigned setting up ExecutionPolicy only for this particular process (...that we run every time we create PowerShell console) and does NOT affect either global, user or any other env ExecutionPolicy variable but variable in this particular process. So it is safe to set up!
P.S. We need to change ExecutionPolicy to be able to run activate script.
References:
Read more about PowerShell startup arguments and ExecutionPolicies.
Answered By - bc-ru Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.