简体   繁体   English

如何在 Homebrew Python 系统中使用 Conda?

[英]How do I use Conda in on Homebrew Python system?

I'm using Homebrew as my package general manager, and am using its Python and pip for software development, along with virtualenvs.我使用 Homebrew 作为我的包总经理,并使用它的 Python 和 pip 以及 virtualenvs 进行软件开发。 For various reasons, I'd like to continue with this structure, but I need some software that is ( apparently ) easier to install using Conda.由于各种原因,我想继续使用这种结构,但我需要一些(显然)更容易使用 Conda 安装的软件。

Can I continue to use Homebrew+pip+virtualev and add Conda into the mix, ideally inside a virtualenv so that it doesn't affect my system as a whole?我可以继续使用 Homebrew+pip+virtualev 并将 Conda 添加到组合中,最好是在 virtualenv 中,这样它就不会影响我的整个系统? If so, how do I set up and use Conda in this way?如果是这样,我该如何以这种方式设置和使用 Conda?


(Python: 2.7.11 (Homebrew); pip: 8.1.1; setuptools: 20.6.7; OS X: 10.11.4 (x86_64)) (Python:2.7.11(Homebrew);pip:8.1.1;setuptools:20.6.7;OS X:10.11.4(x86_64))

You can install Anaconda.您可以安装 Anaconda。 Try brew cask install anaconda .尝试brew cask install anaconda Follow the on-screen instructions you may want to add export PATH=/usr/local/anaconda3/bin:"$PATH" to your ~/.bash_profile or ~/.zsh file.按照屏幕上的说明,您可能希望将export PATH=/usr/local/anaconda3/bin:"$PATH"添加到 ~/.bash_profile 或 ~/.zsh 文件中。

Using anaconda you can create virtual environments for python2 and python3.使用 anaconda,您可以为 python2 和 python3创建虚拟环境。 You can set up environments and then use commands like source activate py27 assuming py27 is an environment you created in python2.7 in anaconda.您可以设置环境,然后使用诸如source activate py27之类的命令,假设py27是您在 anaconda 中的 python2.7 中创建的环境。 It even has GUI and CLI versions.它甚至有 GUI 和 CLI 版本。

Every time I open my terminal, my .bash_profile and .zshrc get sourced.每次我打开终端时,我的 .bash_profile 和 .zshrc 都会被获取。 If you append the source line above, it will load with the version you need everytime.如果您附加上面的source行,它将每次加载您需要的版本。 Every anaconda environment has its own pip as well.每个 anaconda 环境也有自己的 pip。 With Anaconda in the mix, you'd not really need virtualenv anymore but you can keep it if you want.使用 Anaconda,您将不再需要 virtualenv,但您可以根据需要保留它。

If you want to run the Anaconda Navigator GUI you can run it: open /usr/local/anaconda3/Anaconda-Navigator.app .如果你想运行Anaconda Navigator GUI,你可以运行它: open /usr/local/anaconda3/Anaconda-Navigator.app You can use it to manage/create the environments and pip packages, etc.您可以使用它来管理/创建环境和 pip 包等。

I may be wrong but it sounds like the op is trying to figure out how to make a virtual environment for anaconda without overriding all their existing python stuff.我可能是错的,但听起来 op 正试图弄清楚如何为 anaconda 创建一个虚拟环境,而不覆盖他们所有现有的 python 东西。 At least that is what I was trying to do which led me here.至少这就是我试图做的事情,这让我来到了这里。 I managed to find a rather inelegant solution that you can use if you really must have anaconda in its own env:如果你真的必须在自己的环境中拥有 anaconda,我设法找到了一个相当不雅的解决方案:

As devssh says, you can do a brew cask install anaconda but dont add the directory to your path, or it will override your python 2.7 and cause much sadness.正如 devssh 所说,您可以执行brew cask install anaconda不要将目录添加到您的路径中,否则它将覆盖您的 python 2.7 并引起很多悲伤。 Instead create a virtual environment like such (Im using virtual environment wrapper):而是创建一个这样的虚拟环境(我使用虚拟环境包装器):

mkvirtualenv -p /usr/local/anaconda3/bin/python anaconda_env

now move all the stuff from anaconda bin into your virtualenv bin:现在将所有东西从 anaconda bin 移到你的 virtualenv bin 中:

cp /usr/local/anaconda3/bin/* /Users/<you>/.virtualenvs/anaconda_env/bin/

This last is necessary because the anaconda dependencies were not installed with the environments pip so it doesnt know where to look for them.最后一个是必要的,因为 anaconda 依赖项没有与环境 pip 一起安装,所以它不知道在哪里寻找它们。

Perhaps using brew is not recommended but these commands should work也许不推荐使用 brew 但这些命令应该可以工作

# - install python
# install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#  install wget to get miniconda
brew install wget

# get miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

# source /Users/my_username/opt/anaconda3/bin/activate
source ~/miniconda/bin/activate
conda init zsh
conda update -n base -c defaults conda
conda install conda-build

conda create -n iit_synthesis python=3.9
conda activate iit_synthesis
#conda remove --name metalearning2 --all

inspired from:灵感来自:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM