Skip to content

Instantly share code, notes, and snippets.

@jesserobertson
Last active September 1, 2020 22:57
Show Gist options
  • Save jesserobertson/ce1c95e8bd2e86b838a60a3af8b91ecc to your computer and use it in GitHub Desktop.
Save jesserobertson/ce1c95e8bd2e86b838a60a3af8b91ecc to your computer and use it in GitHub Desktop.
Activate the default poetry environment using Powershell
<#
.Synopsis
Activates the current poetry environment
.Description
Run inside your project folder to activate the poetry environment in PowerShell
#>
function Start-PoetryEnv {
$env_folder = $( -split $(poetry env list --full-path) | Select-Object -Index 0)
Invoke-Expression $($env_folder + '\Scripts\Activate.ps1')
}
<#
.Synopsis
Get the location of the Python executable for the current poetry environment
.Description
Prints the path to the python executable in the current poetry environment. Useful
for copying and pasting into VS code since this doesn't actually automatically
discover Poetry envrionments yet.
#>
function Get-PoetryEnv {
$(poetry run where python) | Select-Object -Index 0
}
@jesserobertson
Copy link
Author

jesserobertson commented Aug 31, 2020

Install in $PROFILE with code $PROFILE, restart shell and then you can do start-penv in the base directory of a project to launch the environment.

Use get-penv to set the Python interpreter in VS Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment