Skip to content

Instantly share code, notes, and snippets.

@hsaito
Created June 10, 2019 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsaito/89d202cce88642c98e0908724c1c05d0 to your computer and use it in GitHub Desktop.
Save hsaito/89d202cce88642c98e0908724c1c05d0 to your computer and use it in GitHub Desktop.
Anaconda Initialization Script Module for PowerShell (Windows)
function Initialize-Conda
{
$CONDA_ROOT_DIR = "C:/path/to/Anaconda" # Change this
[System.Environment]::SetEnvironmentVariable("CONDA_EXE", "$CONDA_ROOT_DIR/Scripts/conda.exe", [System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable("_CE_M", "", [System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable("_CE_CONDA", "", [System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable("_CONDA_ROOT", "$CONDA_ROOT_DIR", [System.EnvironmentVariableTarget]::Process)
[System.Environment]::SetEnvironmentVariable("_CONDA_EXE", "$CONDA_ROOT_DIR/Scripts/conda.exe", [System.EnvironmentVariableTarget]::Process)
Import-Module -Scope Global "$Env:_CONDA_ROOT/shell/condabin/Conda.psm1"
conda activate base
}
@LesterCovax
Copy link

ヒーローだよ! 本当に助かた. ありがとうね...

The only thing I had to fix was having the prompt act normally again (with oh-my-posh / posh-git / psreadline). I discovered that it was $Env:_CONDA_ROOT\shell\condabin\Conda.psm1 that was screwing it up, so I commented out lines 268-275, like so...

<#if (Test-Path Function:\prompt) {
    Rename-Item Function:\prompt CondaPromptBackup
} else {
    function CondaPromptBackup() {
        # Restore a basic prompt if the definition is missing.
        "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
    }
}#>

And it finally gave me my prompt back, instead of the otherwise unhelpful PS > prompt.

(Found this from your blog post FYI: https://hideki.hclippr.com/2019/06/09/using-anaconda-from-powershell/)

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