-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activating an environment fails because running powershell scripts is disabled by default on Windows #2559
Comments
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 |
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. @DonJayamanne can we inject some powershell code prior to running |
Yes we can. @d3r3kk |
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 |
Agreed. @qubitron thoughts |
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? |
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 |
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. |
Well, we could do the following:
I.e. where possible use batch files. |
It might also be easier for us to contribute upstream to Python an |
Just to add to the description of the issue at hand I had same problem using Pipenv virtual environment. Pipenv version: 2018.11.14 Worked after updating my execution policy from using the following PS cmdlet: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser Here is the link to the documentation on ExecutionPolicy from Microsoft Cheers |
Not sure if this happens after the latest update but when I execute "Run current file in terminal", it tries to activate the environment that resides in the same directory with the script itself, it fails and afterwards it executes the script with the python interpreter that is inside my environment. How come ? |
@burakcank Is the problem due to Powershell permissions not being set? If so, please run (as admin on your system) the If that is not the problem you are seeing, please feel free to open another issue with the specific details of your situation. |
I was able to work around this problem by adding the following to my VS Code settings: "terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"] |
OPEN POWERSHELL IN ADMINISTRATER MODE AND USE THIS COMMANDS
I hope your problem is solved |
If https://bugs.python.org/issue37354 can be solved then |
This Work on my windows 10 |
Watch python/cpython#14967, may even make it into 3.8. |
@d3r3kk it won't make it into 3.8. |
@luabud @brettcannon we should evaluate other solutions since this won't be fixed within the next 1-2 years on the Python side then. At a minimum, let's make sure to include this step in our getting started docs. |
Works like a charm! Thanks! |
This is not a VS Code issue. Powershell blocks any kind of script by default, not only Python's. |
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. "Conda": {
"source": "PowerShell",
"icon": "terminal-powershell",
"overrideName": true,
"args": ["-ExecutionPolicy", "ByPass", "-NoExit", "-Command", "& 'C:\\Anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\Anaconda3' "]
} EDIT We can create a new configuration setting This appears to work for non-admin users with "restricted" execution policy. |
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:
|
Verification covered by #11039 TPI |
Environment data
Actual behavior
Creating a new terminal in a fresh Windows install results in a powershell error
Expected behavior
I don't need need to disable running scripts in able to use VS code
Steps to reproduce:
The text was updated successfully, but these errors were encountered: