Skip to content

Got error UnauthorizedAccess when extension activating virtual environment #17877

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

Closed
afikrim opened this issue Oct 29, 2021 · 7 comments
Closed
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality

Comments

@afikrim
Copy link

afikrim commented Oct 29, 2021

Environment data

  • VS Code version: 1.62.0-insider
  • Extension version (available under the Extensions sidebar): v2021.11.1393673628-dev
  • OS and version: Windows 11
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: None
  • Relevant/affected Python-related VS Code extensions and their versions: None
  • Value of the python.languageServer setting: Default

Expected behaviour

When starting virtual environment on terminal with type 'powershell', execute 'Set-ExecutionPolicy Unrestricted -Scope Process' -> execute '& "c:/path/to/project/venv/Scripts/Activate.ps1"'

Actual behaviour

Only execute '& "c:/path/to/project/venv/Scripts/Activate.ps1"

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Create a virtual environment with venv
  2. Set your default terminal profile to powershell
  3. Run file or activate virtual environment automatically by opening integrated terminal (make sure you didn't activate 'Set-ExecutionPolicy Unrestricted', you can check it with 'Get-ExecutionPolicy')

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Experiment 'pythonaa' is active
Experiment 'pythonDiscoveryModuleWithoutWatcher' is active
Experiment 'pythonTensorboardExperiment' is active
Experiment 'pythonSurveyNotificationcf' is active
Experiment 'PythonPyTorchProfiler' is active
Experiment 'pythonDeprecatePythonPath' is active
Experiment 'pythonRunFailedTestsButtonDisplayed' is active
Experiment 'pythonRefreshTestsButtonDisplayed' is active
Experiment 'pythonRememberDebugConfig' is active
> conda info --json
> ~\AppData\Local\Programs\Python\Python39\python.exe ~\.vscode-insiders\extensions\ms-python.python-2021.11.1393673628-dev\pythonFiles\interpreterInfo.py
> ~\AppData\Local\Microsoft\WindowsApps\python3.9.exe ~\.vscode-insiders\extensions\ms-python.python-2021.11.1393673628-dev\pythonFiles\interpreterInfo.py
> ~\Downloads\vscode-python\.venv\Scripts\python.exe ~\.vscode-insiders\extensions\ms-python.python-2021.11.1393673628-dev\pythonFiles\interpreterInfo.py
Python interpreter path: .\.venv\Scripts\python.exe
Starting Pylance language server.
> conda --version

@afikrim afikrim added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Oct 29, 2021
@afikrim
Copy link
Author

afikrim commented Oct 29, 2021

I don't know this happens only when using venv or also happens with other virtual environments

Also, I have developed changes needed for fixing this issue, if this only occurred with venv, I'll PR right away.

@karthiknadig karthiknadig self-assigned this Nov 1, 2021
@karthiknadig karthiknadig added triage area-environments Features relating to handling interpreter environments and removed triage-needed Needs assignment to the proper sub-team labels Nov 1, 2021
@karthiknadig
Copy link
Member

This is by design. We don't run Set-ExecutionPolicy Unrestricted -Scope Process since it can change the policy on the machine. This should be done by users as needed to configure the shell they want to use.

@afikrim
Copy link
Author

afikrim commented Nov 2, 2021

I see... But, if we set the -Scope flag to Process, the Unrestricted policy is only available on the current PowerShell session, if we open a new PowerShell session, the execution policy is still the same as before. As mentioned by their documentation here

@afikrim
Copy link
Author

afikrim commented Nov 2, 2021

By default, PowerShell ExecutionPolicy is restricted for a Windows machine. For a new PowerShell user like myself, it'll be annoying when we run our code from an extension and get an error. We always hope there is no error by running our code from an extension

@PhenomRetroShare
Copy link

I agree with @afikrim, at least add an option to make this.
Some bored user may change their system to never have this restriction...

@karthiknadig karthiknadig removed their assignment Nov 29, 2021
@karthiknadig karthiknadig added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Nov 29, 2021
@karthiknadig
Copy link
Member

Changed this to a feature request, since this may require a new setting and UI.

@brettcannon
Copy link
Member

Duplicate of #2559

@brettcannon brettcannon marked this as a duplicate of #2559 Feb 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants