Skip to content

Environment fails to activate when environment path contains special characters #876

@lukas-lang

Description

@lukas-lang

When the extension tries to execute the Activate.ps1 script, it doesn't quote the path, which breaks when the path contains special characters:

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      Job1            BackgroundJob   Running       True            localhost            & C:\Users\Lukas\Documen…
Write-Error: Failed to activate Python environment: The module 'Name' could not be loaded. For more information, run 'Import-Module Name'.

PS C:\Users\Lukas\Documents\Invalid&Name> & C:\Users\Lukas\Documents\Invalid&Name\.venv\Scripts\Activate.ps1

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
3      Job3            BackgroundJob   Running       True            localhost            & C:\Users\Lukas\Documen…
Name\.venv\Scripts\Activate.ps1: The module 'Name' could not be loaded. For more information, run 'Import-Module Name'.

PS C:\Users\Lukas\Documents\Invalid&Name>

The first error comes from the auto-activation when the terminal is created, the second one comes from me manually trying to activate the environment. Note the ampersand in the path (Invalid&Name), which confuses Powershell.

For reference, spaces are properly handled (the environment is already properly auto-activated, I am just pressing the "activate environment" button to show the command explicitly):

(.venv) PS C:\Users\Lukas\Documents\Valid Name> & "C:\Users\Lukas\Documents\Valid Name\.venv\Scripts\Activate.ps1"
(.venv) PS C:\Users\Lukas\Documents\Valid Name> 

Extension Version: 1.8.0, VS Code 1.104.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions