Last active
September 1, 2020 22:57
-
-
Save jesserobertson/ce1c95e8bd2e86b838a60a3af8b91ecc to your computer and use it in GitHub Desktop.
Activate the default poetry environment using Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install in $PROFILE with
code $PROFILE
, restart shell and then you can dostart-penv
in the base directory of a project to launch the environment.Use
get-penv
to set the Python interpreter in VS Code.