How can I install Anaconda aside an existing pyenv installation on OSX?
Not super familiar with conda but I do use pyenv a lot.
Pyenv has its own virtualenv manager that you can use. You can always check which virtualenv version is active with:
pyenv versions
You should see something like:
system
20190814_125309
* 3.7.4 (set by /home/tzhuang/.pyenv/version)
3.7.4/envs/20190814_125309
3.7.4/envs/buildmaster-sandbox
3.7.4/envs/HEAD
3.7.4/envs/myenv
3.7.4/envs/sandbox
buildmaster-sandbox
HEAD
myenv
sandbox
Where the *
indicates the currently active virtualenv (this can be set using pyenv global like you mentioned). You can manually activate any virtualenv with:
pyenv shell
Eg.
pyenv shell sandbox
Then running pyenv versions
gives:
system
20190814_125309
3.7.4 (set by /home/tzhuang/.pyenv/version)
3.7.4/envs/20190814_125309
3.7.4/envs/buildmaster-sandbox
3.7.4/envs/HEAD
3.7.4/envs/myenv
3.7.4/envs/sandbox
buildmaster-sandbox
HEAD
myenv
* sandbox
It's generally a good idea to install any packages you want into a new virtualenv instead of the global virtualenv. It makes it easier to debug environment/dependency issues should you run into any.
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
- Alway initialize
pyenv
, use the Python set bypyenv global
as the default Python - 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
- Getting started with conda
- Using Pip in a Conda Environment, very important
- How do I prevent Conda from activating the base environment by default?