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

use*_*844 26 python pip pypi anaconda conda

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

conda pipbuild [pypi_name]
conda install --use-local [package_spec]
Run Code Online (Sandbox Code Playgroud)

但我不清楚这是否是最佳方式,如果conda update --all在更新可用时更新这些包.我也不清楚当PyPi已经存在时binstar的意义何在.

Chr*_*lan 32

我不同意接受的响应并注意到这pip install [some-pypi-package]通常是在Conda环境中安装PyPi包的最佳方式.

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

当使用蟒蛇,你应该转向condapip时,你可以,但你不会失去任何的当您使用使用蟒蛇的可复制性的好处pip.

  • 需要注意的一个问题是:如果`pip`包需要已经由`conda`安装的不同版本的依赖项,`pip`将替换已安装的包,而`conda`将无法实现其包已被除去.对于一次性脚本环境设置,这可能很好.对于您随着时间的推移手动安装的环境,您可能会在一段时间后感到困惑. (6认同)
  • 缓解上面提到的问题的一种方法是:将`pip freeze`的输出保存到`constraints.txt`然后使用`pip install -c constraints.txt <package>`安装`pip`.这将阻止`pip`删除`conda`包.它还将固定`pip`包.`pip`包可以通过查看标题为`<pip>`的项的`conda list`的输出来过滤出来的`constraints.txt`. (3认同)

asm*_*rer 28

如果要为PyPI包构建conda包,建议的方法是在其创建的配方上使用conda skeleton pypi package和使用conda build package.每次更新包时,您都需要更新配方.

您还可以使用pip安装这些包.这里的缺点是这些包装根本不会由conda管理.

  • 谢谢!愚蠢的问题:管理包裹的公寓能给我带来什么?主要是依赖管理?自动更新?另外,为什么你描述的方法比我上面描述的方法更好? (2认同)
  • conda管理事物可以使您受益于依赖性管理。它还使在conda环境中更轻松地使用该程序包。更新不会“自动”发生(从某种意义上说,您确实需要输入`conda update`才能进行更新)。至于为什么它更可取,“ conda骨架”比“ conda pipbuild”要稳定得多。 (2认同)
  • 注意,您可能需要运行`conda install conda-build`来获取`condaskeleton'命令(我正在使用miniconda)。 (2认同)

Nic*_*ens 5

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
Run Code Online (Sandbox Code Playgroud)

So, the way to get PyPI packages into conda (at the time of writing this) seems to be:

pip install <package>
Run Code Online (Sandbox Code Playgroud)

If you want conda to replace the PyPI packages with its own (where possible), just run:

conda update --all
Run Code Online (Sandbox Code Playgroud)

Given that the above setting is made. Conda marks its own channels as higher priority than pip, thus packages will be replaced.

  • 你的 conda 版本是什么?您可以通过“conda --version”进行检查。我认为你的版本只是早于 4.6.0... (3认同)