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

时间:2023-03-25
本文介绍了OS X - 在 anaconda 和自制 Python 环境之间做出决定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

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

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.

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

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.txt file. 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..)

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

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..

推荐答案

我的所有项目(数据科学、一些 Web 开发)都使用 Homebrew Python.

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

Conda 没有什么花哨的,您可以通过组合 pip 和 自制科学.实际上,它甚至更好,因为您可以更好地控制您安装的内容.

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

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

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.

如果你想用 pip 一次性更新你所有的包,你可以使用这个命令:

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

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

这个答案是旧的,如果你想要一个更最新的比较,我发现这篇不错的博客文章比较了这两种方法:

This answer is old, if you want a more up-to-date comparison, I found this nice blog article which compares the two approaches:

https://towardsdatascience.com/pipenv-vs-conda-for-data-scientists-b9a372faf9d9

我仍然使用 Homebrew Python,并在 conda 上使用 pip/pipenv.

I still use Homebrew Python, and pip / pipenv over conda.

这篇关于OS X - 在 anaconda 和自制 Python 环境之间做出决定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:每当我尝试运行 conda install tensorflow 时都会出现以 下一篇:使用 anaconda 环境运行 crontab 作业

相关文章

最新文章