Python Anaconda 和 Brew 的最佳实践

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42859781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:12:34  来源:igfitidea点击:

Best Practices with Anaconda and Brew

pythonmacoshomebrewanaconda

提问by user2762934

I have just got a new Macbook with OSX Sierra, so want to ensure my development environment is setup properly.

我刚买了一台带有 OSX Sierra 的新 Macbook,所以想确保我的开发环境设置正确。

I am looking to follow the 'best practices' mentioned here: https://github.com/nicolashery/mac-dev-setup

我希望遵循此处提到的“最佳实践”:https: //github.com/nicolashery/mac-dev-setup

I need Python 2.x for work (urllib, Pandas, Numpy, Scikit-learn), and Python 3.x for some online classes (Pandas, Numpy, Django) I am taking. I have installed Python 2 and 3, using brew install pythonand brew install python3respectively.

我需要 Python 2.x 用于工作(urllib、Pandas、Numpy、Scikit-learn)和 Python 3.x 用于我正在学习的一些在线课程(Pandas、Numpy、Django)。我已经分别使用brew install python和安装了 Python 2 和 3 brew install python3

However, on this link, there is no mention of Anaconda, just IPython. Given that I already have Python 2 and 3 installed via Homebrew, is it even advisable to use anaconda, or should I stick to standard IPython as mentioned on the Github link above? I am confused after reading this post: OS X - Deciding between anaconda and homebrew Python environments

但是,在此链接上,没有提及 Anaconda,仅提及 IPython。鉴于我已经通过 Homebrew 安装了 Python 2 和 3,是否建议使用 anaconda,或者我应该坚持使用上面 Github 链接中提到的标准 IPython?读完这篇文章后我很困惑:OS X - 在 anaconda 和自制 Python 环境之间做出决定

If Brew and Anaconda can indeed work together, what specific steps can I take to ensure that there are no conflicts between the two versions?

如果 Brew 和 Anaconda 确实可以一起工作,我可以采取哪些具体步骤来确保两个版本之间没有冲突?

回答by apollo

I am new to python, and have had trouble with my python installation. I have both python installation from homebrew and anaconda on my mac. My anaconda installation had messed up my homebrew python dependency for vim and MacVim.

我是 python 新手,在安装 python 时遇到了问题。我的 Mac 上同时安装了自制软件和 anaconda 的 python 安装。我的 anaconda 安装搞砸了我对 vim 和 MacVim 的自制 python 依赖。

My solution is whenever I am installing/update package via homebrew I would remove anaconda from my PATH. This is a bit of a pain, but I only installing/updating package via homebrew once in a while so it okay.

我的解决方案是每当我通过自制软件安装/更新软件包时,我都会从我的 PATH 中删除 anaconda。这有点痛苦,但我只是偶尔通过自制软件安装/更新软件包,所以没关系。

To switch between python 2 and 3 here are my commands in Terminal:

要在 python 2 和 3 之间切换,这是我在终端中的命令:

$ conda search python
...
...
$ conda install python=3.5.0

$ conda info -e
# conda environments:
#
py27                     /Users/apollotang/opt/local/anaconda2/envs/py27
py36                     /Users/apollotang/opt/local/anaconda2/envs/py36
root                  *  /Users/apollotang/opt/local/anaconda2

$ source activate py36      ### <——— here is the command in to change python version 
(py36) $ conda info -e
# conda environments:
#
py27                     /Users/apollotang/opt/local/anaconda2/envs/py27
py36                  *  /Users/apollotang/opt/local/anaconda2/envs/py36
root                     /Users/apollotang/opt/local/anaconda2

(py36) $ python -V
Python 3.6.2 :: Anaconda custom (x86_64)

I found this command from How to change default Anaconda python environmentand http://chris35wills.github.io/conda_python_version/

我从如何更改默认的 Anaconda python 环境http://chris35wills.github.io/conda_python_version/ 中找到了这个命令

Also, here is a very good article on best practice on setting up python environment on mac https://www.davidculley.com/installing-python-on-a-mac/

另外,这里有一篇关于在 mac 上设置 python 环境的最佳实践的非常好的文章 https://www.davidculley.com/installing-python-on-a-mac/

回答by holdenweb

Installing anacondawould mean you have no need of the system Python (leave it to the system, since you probably don't want to change it), or of Pythons installed by homebrew.

安装anaconda意味着您不需要系统 Python(将它留给系统,因为您可能不想更改它)或由homebrew.

When you create a condaenvironment you can specify which version of Python you want it to use. For example:

创建conda环境时,您可以指定要使用的 Python 版本。例如:

$ conda create --name myenv python=3.5

Activating a condaenvironment (after the above command you'd do this with conda activate myenv, or source activate myenvfor earlier versions) automatically means that the pythoncommand will run the Python interpreter you selected for that environment. Packages can be installed with pipas well as conda install, and are pretty much compatible with condaenvironments.

自动激活conda环境(在上述命令之后,您将使用conda activate myenv,或source activate myenv对于早期版本执行此操作)意味着该python命令将运行您为该环境选择的 Python 解释器。软件包可以与pip以及一起安装conda install,并且几乎与conda环境兼容。

回答by pdel5

You can set up a virtual environment (virtualenv) and assign different versions Python to each so there wouldn't be any overlap causing dependency issues.

您可以设置一个虚拟环境 (virtualenv) 并为每个环境分配不同的 Python 版本,这样就不会有任何重叠导致依赖问题。

Check out 'The Hitchhiker's Guide to Python' on how to walk through the setup.

查看“The Hitchhiker's Guide to Python”了解如何完成设置。

http://docs.python-guide.org/en/latest/dev/virtualenvs/

http://docs.python-guide.org/en/latest/dev/virtualenvs/