除了 OSX 上现有的 pyenv 安装之外,如何安装 Anaconda?

2022-01-10 00:00:00 python macos pyenv anaconda homebrew

问题描述

如果这在其他地方很容易找到,我们深表歉意,但尽管我找到了一些带有 pyenv 和 Anaconda 解释的帖子,但没有一个专门解决这个问题.但是,我经常是个白痴.

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.

在 Mac OSX (Mojave 10.14.6) 上,我通过 Homebrew 安装了 pyenv

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

brew install pyenv

我很乐意安装并在 Python 版本之间切换

And I happily install and switch between Python versions with

pyenv 安装 ...

pyenv 全局 ...

我通常使用 VS Code 作为我的 IDE.

I typically use VS Code as my IDE.

我现在需要在 Anaconda 中做一些工作.我以前没用过.我可以简单地安装 Anaconda 通过分发站点 并使用它的导航器,当我需要旧的 python 版本时使用pyenv和VS Code,还是安装Anaconda的时候会冲突?如果会发生冲突,是否有在 OSX 上同时运行两者的路径?

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?

我当然可以安装它,看看会发生什么,如果它很乱,可以从备份中恢复.但我希望 pyenv/Anaconda 大师可能会提出一些明智的建议,这可能会节省我数小时的清理时间.

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.

提前致谢!


解决方案

有冲突,导致 pyenvconda 都尝试默认暴露全局 Python 环境.

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. 始终初始化pyenv,使用pyenv global设置的Python作为默认Python
  2. 仅公开命令 conda 但不激活任何环境
  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

详情

由于你的机器上已经安装了pyenv,你只需要安装Anaconda即可.

Detail

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

brew cask install anaconda

初始化 conda 而不暴露 conda 的基础"环境.

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

完成.

注意:在此设置之后,默认的 Python 是 pyenv global 设置的那个.使用 pyenvconda 分别管理环境.

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

管理虚拟环境的示例.

# 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

pyenv 的默认环境位置是 ~/.pyenv/versions.

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

conda 的默认环境位置,检查 conda info 的输出.

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

  • conda 入门李>
  • 在 Conda 环境中使用 Pip,非常重要
  • 如何防止 Conda 默认激活基础环境?

相关文章