You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Activating an environment fails because running powershell scripts is disabled by default on Windows #2559
Extension version (available under the Extensions sidebar): 2018.8.0
OS and version: Windows 10
Python version (& distribution if applicable, e.g. Anaconda): Python 3.7..0
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
Relevant/affected Python packages and their versions: N/A
Actual behavior
Creating a new terminal in a fresh Windows install results in a powershell error
PS C:\dev\loadtest> & c:/dev/loadtest/env/Scripts/activate.ps1
& : File C:\dev\loadtest\env\Scripts\activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ & c:/dev/loadtest/env/Scripts/activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Expected behavior
I don't need need to disable running scripts in able to use VS code
Hmmm.. this feels like it might be a VSCode problem.
To fix the issue, you can simply open a Powershell window as administrator and type the following:
Set-ExecutionPolicy RemoteSigned
And hit enter, respond y to any prompts that appear.
Reacted by A86S, Caleb Collins-Parks, فارس بالسرور, Dmitriy Dulkin, karimoons, Jiawei Tang, Bruce Liu, Ali Hussein Al-Issa, Samuel R. Rivera, DongJun and 195 more
Reacted by Kartikey Shaurya, Kartik Raj, Sarthak Sahu, Marco N, Hrithik Saxena, Surya Pratap, Sarath Chandra, Chedy Chaaben, Mohit Chouhan, Sadegh Rezaei and 18 more
Reacted by Abdul Hannan Kamrul, Kartik Raj, Sarthak Sahu, Marco N, Hamza Chundrigar, Hrithik Saxena, Johnathon T. Salfer, Osama Ishaq, Pargavi Selvaraj, Surya Pratap and 23 more
Reacted by Zia mohe uddin, Nigusu Kassahun, Chetan Surwade, Hrithik Saxena, Johnathon T. Salfer, Osama Ishaq, Surya Pratap, tot-samij88, sushantdev, Chedy Chaaben and 46 more
Reacted by Will, Mateus Talles, Chintapalli , ThankGod Egbe, Minh Dang, Jagdish Choudhary, Oliveira Prado, Aref, Agnibha Mukherjee, Ala Eddine Abbassi and 4 more
Reacted by Chintapalli , Oliveira Prado, Aref, Agnibha Mukherjee, Akash Kumar and st-eugen
I take it back - we are running an activate.ps1 file from a .venv!
Hmmm... not sure what we can do about this from the extension's perspective. Don Jayamanne (@DonJayamanne) can we inject some powershell code prior to running activate.ps1 when we launch a python terminal?
can we inject some powershell code prior to running activate.ps1 when we launch a python terminal?
Yes we can.
Changing the label, as this isn't a bug. we're trying to improve the UX for users of the extension.
Derek Keeler (@d3r3kk)
Your original suggestion works, changing the policy will work, however Dan Taylor (@qubitron) doesn't want to have to do it manually.
Basically we should do what ever we can to remove/reduce such road blocks.
changed the title [-]activate.ps1 fails because running scripts is disabled by default on Windows[/-][+]Activating an environment fails because running powershell scripts is disabled by default on Windows[/+]on Sep 12, 2018
Yep, that's pretty standard Powershell behaviour/expected workflow on a new machine. Not sure we should usurp that is what I'm getting at.
However, if we choose to do so, it shouldn't be too difficult to put a quick popup and ask the user if doing so will be ok with them first (much like the powershell cmdlet Set-ExecutionPolicy does).
This will require elevation to set the execution policy correct? Not all users have admin rights on the system
What if the user doesn't want this execution policy set for security reasons, it's off by default for a reason?
Why do we even need powershell cmdlet to do this, why can't we run a batch file or something else that doesn't require admin privileges/execution policies to be set?
The other option any notification could have is offer to switch off the automatic activation on top of providing instructions on how to change the policy.
OK, so really this is an issue because we're using a powershell cmd prompt instead of CMD (which is what I use outside of VS Code and just lets me activate without having to set any policies).
Since I assume we can't change the default from powershell to cmd, detecting the issue and prompting users to set the execution policy (with a button) seems like the right solution.
I think this may actually be a working solution via a terminal profile, since it mimics the specifications of the Anaconda PowerShell Prompt shortcut that gets placed in the start menu when Anaconda is installed. Here I've made a "Conda" profile, but you could also add the "args" entry to your default PowerShell profile.
EDIT We can create a new configuration setting "python.condaHome" : "C:\\Anaconda3" and insert it into the Conda terminal profile arguments via ${config:python.condaHome}.
This appears to work for non-admin users with "restricted" execution policy.
Activity
d3r3kk commentedon Sep 12, 2018
Hmmm.. this feels like it might be a VSCode problem.
To fix the issue, you can simply open a Powershell window as administrator and type the following:
Set-ExecutionPolicy RemoteSignedAnd hit enter, respond
yto any prompts that appear.d3r3kk commentedon Sep 12, 2018
I take it back - we are running an activate.ps1 file from a .venv!
Hmmm... not sure what we can do about this from the extension's perspective. Don Jayamanne (@DonJayamanne) can we inject some powershell code prior to running
activate.ps1when we launch a python terminal?DonJayamanne commentedon Sep 12, 2018
Yes we can.
Changing the label, as this isn't a bug. we're trying to improve the UX for users of the extension.
Derek Keeler (@d3r3kk)
Your original suggestion works, changing the policy will work, however Dan Taylor (@qubitron) doesn't want to have to do it manually.
Basically we should do what ever we can to remove/reduce such road blocks.
[-]activate.ps1 fails because running scripts is disabled by default on Windows[/-][+]Activating an environment fails because running powershell scripts is disabled by default on Windows[/+]d3r3kk commentedon Sep 12, 2018
Yep, that's pretty standard Powershell behaviour/expected workflow on a new machine. Not sure we should usurp that is what I'm getting at.
However, if we choose to do so, it shouldn't be too difficult to put a quick popup and ask the user if doing so will be ok with them first (much like the powershell cmdlet
Set-ExecutionPolicydoes).DonJayamanne commentedon Sep 12, 2018
Agreed.
After all, we're executing some script that we have no control over.
Dan Taylor (@qubitron) thoughts
qubitron commentedon Sep 12, 2018
Why do we even need powershell cmdlet to do this, why can't we run a batch file or something else that doesn't require admin privileges/execution policies to be set?
brettcannon commentedon Sep 12, 2018
It's a PowerShell script because that's how you get the prompt updated to list the virtual environment's name: https://github.com/python/cpython/blob/master/Lib/venv/scripts/nt/Activate.ps1
brettcannon commentedon Sep 12, 2018
The other option any notification could have is offer to switch off the automatic activation on top of providing instructions on how to change the policy.
qubitron commentedon Sep 12, 2018
OK, so really this is an issue because we're using a powershell cmd prompt instead of CMD (which is what I use outside of VS Code and just lets me activate without having to set any policies).
Since I assume we can't change the default from powershell to cmd, detecting the issue and prompting users to set the execution policy (with a button) seems like the right solution.
70 remaining items
mkoohafkan commentedon Aug 18, 2023
I think this may actually be a working solution via a terminal profile, since it mimics the specifications of the Anaconda PowerShell Prompt shortcut that gets placed in the start menu when Anaconda is installed. Here I've made a "Conda" profile, but you could also add the "args" entry to your default PowerShell profile.
EDIT We can create a new configuration setting
"python.condaHome" : "C:\\Anaconda3"and insert it into the Conda terminal profile arguments via${config:python.condaHome}.This appears to work for non-admin users with "restricted" execution policy.
karrtikr commentedon Sep 11, 2023
We have a new activation mechanism #11039 which does not require executing any script, hence does not run into this issue, give it a try:
Tyriar commentedon Sep 26, 2023
Verification covered by #11039 TPI