如何使用 anaconda conda 命令安装 PyPi 包

How to install PyPi packages using anaconda conda command

使用 Anacoda Python 发行版时,安装不能直接通过 Anaconda 获得的 PyPi 包的最佳方法是什么?现在我正在使用:

conda pipbuild [pypi_name]
conda install --use-local [package_spec]

但我不清楚这是否是最好的方法,以及 conda update --all 是否会在更新可用时更新这些包。我也不清楚当 PyPi 已经存在时 binstar 的意义是什么。

如果你想为 PyPI 包构建 conda 包,推荐的方法是使用 conda skeleton pypi package 并在它创建的配方上使用 conda build package。要安装包,请使用 conda install --use-local package(此处和其他地方,package 是您要安装的 PyPI 包的名称)。

每次更新包时您都需要更新食谱。

您也可以使用 pip 安装这些软件包。有两个缺点:首先,这些包根本不会被 conda 管理。其次,如果您的默认 python 版本与您在 conda 中使用的 python 版本不同,这些包将无法工作。

我不同意已接受的回复,请注意 pip install [some-pypi-package] 通常是在 Conda 环境中安装 PyPi 包的最佳方式。

虽然包不会由 Conda 包管理器管理,但它们仍将由 Anaconda 环境管理。它将为活动的 Python 安装下载正确版本的包,并使用 pip 包管理器正确更新它。

使用 Anaconda 时,您应该尽可能在 pip 之前转向 conda,但是当您使用 pip 时,您不会失去使用 Anaconda 的任何可复制性优势.

Anaconda 最近发布了一个支持这一点的文档:https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment

version 4.6.0 以来,Conda 改进了与 pip 的互操作性:

Conda and pip have historically had difficulties getting along. Pip hasn’t respected Conda’s environment constraints, while Conda has been all too happy to clobber pip-installed software. It’s a mess. Conda 4.6.0 adds preview support for better interoperability. With this interoperability, Conda can use pip-installed packages to satisfy dependencies, and can even remove pip-installed software cleanly and replace them with Conda packages when appropriate. There’s still room for improvement before pip and Conda are hunky-dory BFFs, but we hope this is a good start. This feature is disabled by default right now because it can significantly impact Conda’s performance. If you’d like to try it, you can set this condarc setting:

conda config --set pip_interop_enabled True

因此,将 PyPI 包导入 conda 的方法(在撰写本文时)似乎是:

pip install <package>

如果您希望 conda 用自己的包替换 PyPI 包(如果可能),只需 运行:

conda update --all

鉴于以上设置。 Conda 将自己的频道标记为比 pip 更高的优先级,因此包将被替换。