How to display conda's environment in zsh (not using oh-my-zsh)?
Asked Answered
F

5

7

I use zsh but not equipted with oh-my-zsh, since I cloned many git repos on my machine and oh-my-zsh's default theme or 'josh' theme makes it very slow, for cd and ls commands, etc.

Thus I delete oh-my-zsh and only use zsh's default recommended config, except adding some alias and path variables.

Now comes the question: I manage my python environment by conda, and no current enviroment name displayed in my prompt.

I have executed the command:

conda init zsh

And re-open my terminal (default shell is zsh), still not display "(base)" or "(py36)" stuffs.

How can I tell my terminal to show that stuff? The git branch does not matters for my work, but the current python version really matters, since DeepLearning related tools use many different python versions.

Farly answered 25/11, 2019 at 13:36 Comment(1)
In my ~/.condarc, I previously didn't setting changeps1: False. And now I add changeps1: True, still not work.Farly
F
2

This was caused due to this line in default zsh's config:

prompt adam1

Once delete that line, re-open terminal, conda environment are shown.

Farly answered 25/11, 2019 at 13:52 Comment(3)
Where can I find this?Irmgard
@Irmgard Find it in your zsh config file, usually it is ~/.zshrcFarly
I don't have such a line. But still, conda env is not shown.Irmgard
V
9

For those users with oh-my-zsh

I add anaconda element in ~/.zshrc config file

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda ...ENVS)

and the conda env shows up

Vanegas answered 29/1, 2021 at 5:56 Comment(0)
C
3

If you're not using oh-my-zsh and have not copy-pasted the relevant sections from there, then the correct answer is that when you do conda init zsh, the environment variable CONDA_PROMPT_MODIFIER is introduced. You want to add that to your PROMPT. You should do so as part of the precmd function, so that the an updated value of the environment variable is shown every time a prompt is printed.

Cornemuse answered 28/5, 2021 at 3:19 Comment(0)
F
2

This was caused due to this line in default zsh's config:

prompt adam1

Once delete that line, re-open terminal, conda environment are shown.

Farly answered 25/11, 2019 at 13:52 Comment(3)
Where can I find this?Irmgard
@Irmgard Find it in your zsh config file, usually it is ~/.zshrcFarly
I don't have such a line. But still, conda env is not shown.Irmgard
A
0

You can try,

# init your shell first
conda init zsh
source ~/.zshrc # refresh your shell
source activate base # (optional, on linux) activate base env
Auscultation answered 12/1, 2021 at 11:57 Comment(1)
by running conda init zsh, some init lines wil be added to ~/.zshrc . Then do source ~/.zsh, is the same as re-open a shell. The last step you mentioned, source activate base, I didn't try, but it can also be put in ~/.zshrc.Farly
S
0

I just moved changeps1: False this line in ~/.condarc,and restart my zsh, the (base) suddenly appear.

It takes effort to me!

Style answered 19/7, 2023 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.