Skip to content

Instantly share code, notes, and snippets.

@emredjan
Last active November 22, 2018 13:51
Show Gist options
  • Save emredjan/9044bb28f870f5f8b158d766da0db544 to your computer and use it in GitHub Desktop.
Save emredjan/9044bb28f870f5f8b158d766da0db544 to your computer and use it in GitHub Desktop.
Activate conda environment in PowerShell
Param
(
[parameter(Position=0, Mandatory=$true)]
[String]
$env_name
)
# simulate activation of Conda environment
$cenv = "C:\Path\to\anaconda\installation\envs\$env_name"
$Env:CONDA_PREFIX = $cenv
$Env:CONDA_DEFAULT_ENV = $env_name
$Env:PATH = "$cenv;$cenv\Library\mingw-w64\bin;$cenv\Library\usr\bin;$cenv\Library\bin;$cenv\Scripts;$cenv\bin;$Env:PATH"
# add env name to prompt
function global:UserPrompt {''}
$Function:UserPrompt = $Function:prompt
function global:prompt
{
"($Env:CONDA_DEFAULT_ENV) " + (UserPrompt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment