Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

python - How can I install Anaconda aside an existing pyenv installation on OSX?

Sincerest apologies if this is easily found elsewhere, but although I found a number of posts with pyenv and Anaconda explanations, none addressed this issue specifically. However, I am often an idiot.

On Mac OSX (Mojave 10.14.6) I installed pyenv via Homebrew

brew install pyenv

And I happily install and switch between Python versions with

pyenv install ...

and

pyenv global ...

I typically use VS Code as my IDE.

I now have need to do some work in Anaconda. I haven't used it before. Can I simply install Anaconda via the distribution site and use its navigator, and when I need my old python versions use pyenv and VS Code, or will there be a conflict when I install Anaconda? If there would be a conflict, is there a path to running both on OSX?

I could install it and see what happens of course, and restore from backup if it's a big mess. But I'm hoping that a pyenv / Anaconda guru might have some sage words of advice that would save me potentially hours of cleaning up.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is a conflict, cause both pyenv and conda try to expose a global Python environment by default.

I've been using these tools together and best solution found by me is to

  1. Alway initialize pyenv, use the Python set by pyenv global as the default Python
  2. Only expose command conda but do NOT activate any environment from it

Detail

Since pyenv has been installed on your machine, you only need to install Anaconda.

brew cask install anaconda

Init conda without exposing the "base" environment from conda.

# init conda, the following command write scripts into your shell init file automatically
conda init

# disable init of env "base"
conda config --set auto_activate_base false

Done.

Note: After this setup, the default Python is the one set by pyenv global. Use pyenv and conda to manage environments separately.

Examples of managing virtual environments.

# virtual environments from pyenv
pyenv install 3.6.9
pyenv virtualenv 3.6.9 new-env
pyenv activate new-env
pyenv deactive
# You can also use `pyenv local`


# virtual environments from conda
conda create -n new-env python=3.6
conda env list
conda activate new-env
conda deactivate

Default env location for pyenv is ~/.pyenv/versions.

Default env location for conda, check output from conda info.

Extended Readign


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...