OS X - 在 anaconda 和自制 Python 环境之间做出决定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33541876/
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 13:32:23  来源:igfitidea点击:

OS X - Deciding between anaconda and homebrew Python environments

pythonmacosnumpyhomebrewanaconda

提问by user1496984

I use Python extensively on my Mac OS X, for both numerical applications and web development (roughly equally). I checked the number of Python installations I had on my laptop recently, and was shocked to find four:

我在 Mac OS X 上广泛使用 Python,用于数值应用程序和 Web 开发(大致相同)。我检查了我最近在笔记本电脑上安装的 Python 的数量,震惊地发现了四个

Came with Mac OS X:
/usr/bin/python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin

Installed via Homebrew
/usr/local/bin/python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin

Installed via Anaconda/Miniconda
~/anaconda/bin/python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Oct 19 2015, 18:31:17)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org

Came with the downloaded .pkg from python.org
/System/Library/Frameworks/Python.framework/Versions/Current/bin/python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin

I decided to unify all of this, and use conda. I removed the Homebrew version and the Python.org download (kept the main system one). Conda is great for numerical computing, because I can install Jupyter/Numpy/Pandas in the root environment, and not have to bother install virtualenvs for every project.

我决定统一所有这些,并使用conda. 我删除了 Homebrew 版本和 Python.org 下载(保留主系统版本)。Conda 非常适合数值计算,因为我可以在 root 环境中安装 Jupyter/Numpy/Pandas,而不必费心为每个项目安装 virtualenvs。

But now my entire web development workflow is messed up. None of my virtualenvs work, since apparently one's not supposed to use conda and virtualenv together. I tried to create conda environments from the requirements.txtfile. One package I was using with django was "markdown_deux", which is not available in the Conda repo. I looked at ways of building it, but creating a recipe takes a lot of effort (create YAML file, etc..)

但是现在我的整个 Web 开发工作流程都搞砸了。我的 virtualenv 都不起作用,因为显然不应该同时使用 conda 和 virtualenv。我试图从requirements.txt文件创建 conda 环境。我在 django 中使用的一个包是“markdown_deux”,它在 Conda 存储库中不可用。我研究了构建它的方法,但是创建一个配方需要很多努力(创建 YAML 文件等。)

Has anyone found a good compromise for this? I'm thinking of going back to the homebrew version for general use, and writing an alias for changing the path back to the conda version as necessary. Though this will also require tracking which one I'm using now..

有没有人为此找到一个好的妥协?我正在考虑回到 homebrew 版本以供一般使用,并根据需要编写别名以将路径更改回 conda 版本。虽然这也需要跟踪我现在使用的是哪一个..

采纳答案by Kirell

I use Homebrew Python for all my projects (data science, some web dev).

我将 Homebrew Python 用于我的所有项目(数据科学、一些网络开发)。

Conda is nothing fancy, you can have the same packages by hand with a combination of pipand Homebrew science. Actually, it is even better because you have more control on what you install.

康达是没有任何幻想,你可以通过手的组合具有相同的包pip自制的科学。实际上,它甚至更好,因为您可以更好地控制安装的内容。

You can use your virtualenvs only when you do web development. For the numerical applications you will probably want to have the latest versions of your packages at all times.

只有在进行 Web 开发时才能使用 virtualenv。对于数值应用程序,您可能希望始终拥有最新版本的软件包。

If you want to update all your packages at once with pip, you can use this command:

如果要使用 pip 一次更新所有包,可以使用以下命令:

sudo -H pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 sudo -H pip install -U

回答by Rebs

Workflow that I've found the best:

我发现最好的工作流程:

  • Use condafor virtual environment management. Neveruse / install into system python.

  • Use pipto install into the active virtual environment, just like normal.

  • Use condapackages onlyfor hard to install software, such as Qt.

  • 使用conda虚拟环境的管理。永远不要使用 / install 到系统 python 中。

  • 使用pip安装到活动的虚拟环境,就像正常的。

  • conda软件包用于难以安装的软件,例如 Qt。

Automation / extras

自动化/附加功能

  • Use autoenvor direnvand automatically activate virtual environments when you enter a directory by putting the conda command inside the .envor .envsrcfile.
  • 通过将 conda 命令放入or文件中,在进入目录时使用autoenvordirenv和自动激活虚拟环境。.env.envsrc