Reputation: 79
tried to install anaconda on my friend's PC and run into this problem[I fixed it, but couldn't find an answer so i want to post it here] the PC just wont load anaconda environment, when you type
>>conda activate base
>>conda info
active environment : None
python works but with this warning
>> python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
>>>
Upvotes: 2
Views: 2925
Reputation: 438153
It sounds like what your own answer does with custom code - adding Conda activation code to PowerShell's profile (initialization file), $PROFILE
- already comes prepackaged with conda
's init
command:
conda init powershell
See the docs or run conda init --help
.
Note, however, that there seems to be an issue with activating yet another base environment when Conda is initialized globally this way.
A comment in the linked issue from March 2019 states:
In the meantime, you should be able to
conda install powershell_shortcut
to use the alternative way that does not requireconda init
. It has not seen much testing, so any feedback you have is welcome and appreciated.
Upvotes: 4
Reputation: 5681
Have you tried conda activate base
instead of just activate base
?
On my system get-command activate
shows that activate
picks up activate.bat
which is not powershell-aware. conda
binds to a powershell function created by the conda ps module.
It seems that the powershell hook is adding too much to path, but it is not clear to me what the intended setup is.
Edit:
Just added the following to my profile.ps1
to get activate
/deactivate
working. Only drawback is that you don't get tab-completion this way.
function anaconda_activate([string]$environment) {invoke-conda activate $environment}
New-Alias -Force activate anaconda_activate
function anaconda_deactivate {invoke-conda deactivate}
New-Alias -Force deactivate anaconda_deactivate
Upvotes: 0
Reputation: 79
So how to fix:
First we need to enable scripts in powershell so we run this.
PS> Set-ExecutionPolicy Unrestricted -Force
This answer is anywhere in the internet but in my case it didn't fix the issue. in my case the powershell didn't have a profile and those didnt load the necessary stuff.
so we need to create a profile, by typing into powershell:
PS> New-Item –Path $Profile –Type File –Force
that would create a new profile file.
like profile.ps1
in \Documents\WindowsPowerShell\
then we will add the following code into the file
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "$PathToAnaconda\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
and this is it, next time you open a PowerShell session you would get this message,
Loading personal and system profiles took 1453ms.
and environments should work just fine.
Upvotes: 1