如何使用 anaconda 安装来自 Requirement.txt in python 的软件包?

How to install packages from Requirement.txt in python using anaconda?

我对如何安装其他人为 python 项目共享的 requirements.txt 中的所有软件包感到困惑,严格使用Anaconda 仅在 Windows os.

  1. 我已经安装了 Anaconda 导航器。我应该在导航器中还是在 conda 提示符下执行此操作?
  2. 我是否需要先创建一个环境,然后激活它,然后在该环境中 运行 命令 pip install requirements.txt

请问,您能否建议一种更好的方法来使用 requirements.txt 和 运行 python 项目从 anaconda 安装软件包?

在终端中 window 您可以输入:

pip install -r requirements.txt

您需要输入 requirements.txt

的完整路径

C:\Users[用户名]\Desktop\requirements.txt

您还可以在此处查看此描述:

https://note.nkmk.me/en/python-pip-install-requirements/

conda 使用 environment.yaml 文件而不是 requirements.txt,但您可以在另一个文件中包含一个:

# environment.yaml

name: test-env
dependencies:
  - python>=3.5
  - anaconda
  - pip
  - pip:
    - -r file:requirements.txt

然后使用conda通过

创建环境
conda env create -f environment.yaml

通过以下命令使用 Conda 在 requirements.txt 中安装软件包时

conda install --yes --file requirements.txt