简体   繁体   English

如何使用 anaconda 从 python 中的 Requirement.txt 安装包?

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

I am confused on how to install all the packages from requirements.txt shared by another person for a python project strictly using Anaconda only in Windows os .我对如何仅在 Windows 操作系统中严格使用 Anaconda安装另一个人为 python 项目共享的 requirements.txt 中的所有软件包感到困惑。

  1. I have installed Anaconda navigator.我已经安装了 Anaconda 导航器。 Should I do it in navigator or in conda prompt?我应该在导航器中还是在 conda 提示符下进行?
  2. Do I need to create an environment first and then activate it and then run command pip install requirements.txt in that environment?我是否需要先创建一个环境然后激活它,然后在该环境中运行命令pip install requirements.txt

Please, could you suggest a better way to install the packages from anaconda using requirements.txt and run the python project?拜托,你能建议一种更好的方法来使用 requirements.txt 从 anaconda 安装软件包并运行 python 项目吗?

In a terminal window you can enter:在终端窗口中,您可以输入:

pip install -r requirements.txt

You will need to enter the full path of the requirements.txt您需要输入requirements.txt的完整路径

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

You can also see this described here:您还可以在此处看到此描述:

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

conda uses an environment.yaml file instead of requirements.txt , but you can include one in the other: conda 使用environment.yaml文件而不是requirements.txt ,但您可以在另一个文件中包含一个:

# environment.yaml

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

Then use conda to create the environment via然后使用 conda 通过创建环境

conda env create -f environment.yaml

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

conda install --yes --file requirements.txt

Kate, your question and terminology should be more precise.凯特,你的问题和术语应该更准确。

First, I will answer your question... Then I will go into more detail with more precise terminology for others who have the same questions.首先,我会回答你的问题......然后我会 go 更详细地为其他有相同问题的人提供更准确的术语。

CONVERT REQUIREMENTS.TXT TO ENVIRONMENT.YML FILE将 REQUIREMENTS.TXT 转换为 ENVIRONMENT.YML 文件

The best way to use a conda and a requirements.txt (the pip package manager installation specification) is to convert the requirements.txt file into an environment.yml file.使用 conda 和 requirements.txt(pip package 管理器安装规范)的最佳方法是将 requirements.txt 文件转换为 environment.yml 文件。 To do this, copy the names of all packages from the requirements.txt file into an environment.yml file.为此,将所有包的名称从 requirements.txt 文件复制到 environment.yml 文件中。 Make sure the environment.yml file is properly formatted.确保 environment.yml 文件格式正确。

See this link for examples of environment.yml file formatting:有关 environment.yml 文件格式的示例,请参阅此链接:

[Creating an environment file][1] Then use conda from the command line and specify the environment.yml file in your conda command at the console. [创建环境文件][1] 然后从命令行使用 conda,并在控制台的 conda 命令中指定 environment.yml 文件。

Try this automated script to read and use requirements.txt in conda "on the fly".尝试使用此自动化脚本在 conda 中“即时”读取和使用 requirements.txt。 [Install only available packages using "conda install --yes --file requirements.txt" without error][2] [使用“conda install --yes --file requirements.txt”只安装可用的包没有错误][2]

BUILDING THE ENVIRONMENT GRAPHICALLY USING ANACONDA NAVIGATOR:使用 ANACONDA NAVIGATOR 以图形方式构建环境:

A purely graphical (and manual) alternative is to use the Anaconda Navigator Package Manager GUI.纯图形(和手动)替代方法是使用 Anaconda Navigator Package Manager GUI。 Individually select each file specified in the requirements.txt file using the Package Manager interface (see image). select 使用 Package 管理器界面在 requirements.txt 文件中指定每个文件(见图)。 Select each green check mark for the desired package in the right-hand column. Select 右侧栏中所需 package 的每个绿色复选标记。 Then click the "Apply" button.然后单击“应用”按钮。 If the package exist in Anaconda Navigator, then this graphical approach will work.如果 package 存在于 Anaconda Navigator 中,则此图形方法将起作用。

[![Graphical Environment and Package Manager in Anaconda Navigator][3]][3] [![Anaconda 导航器中的图形环境和 Package 管理器][3]][3]

############################## ##############################

CLARIFYING TERMINOLOGY about 5 snakes and 1 pip;^)澄清关于 5 条蛇和 1 条 pip 的术语;^)

There is a body of distinct terminology and semantics in this area.在这个领域有大量不同的术语和语义。

  1. the "anaconda package", “蟒蛇包”,
  2. the "Anaconda desktop" (Navigator) “Anaconda 桌面”(导航器)
  3. the "Anaconda distribution", “蟒蛇分布”,
  4. the "conda utility", “康达实用程序”,
  5. the "conda package", “康达包”,
  6. the "pip utility" “pip 实用程序”
  7. the "pip package", “点子包”,
  8. related topics (read on...)相关主题(继续阅读...)

When you say "anaconda", you probably mean the "Anaconda Navigator Desktop" graphical user interface, not the python package "anaconda" that gets installed at a terminal command line using conda or pip.当您说“anaconda”时,您可能指的是“Anaconda Navigator Desktop”图形用户界面,而不是使用 conda 或 pip 在终端命令行安装的 python package “anaconda”。

The "anaconda" (lower case) package is for supporting automated installation of the "Anaconda Distribution" and the "Anaconda Navigator GUI Desktop". “anaconda”(小写)package 用于支持自动安装“Anaconda Distribution”和“Anaconda Navigator GUI Desktop”。

The "Anaconda Navigator" is the desktop program shipped with the Anaconda.com distribution. “Anaconda Navigator”是 Anaconda.com 发行版附带的桌面程序。 It provides GUI functions for managing environments and packages within conda environments.它提供用于管理 conda 环境中的环境和包的 GUI 功能。

Under the covers the Anaconda Navigator "environment manager" executes the commands using the "conda" command line utility.在幕后,Anaconda 导航器“环境管理器”使用“conda”命令行实用程序执行命令。 Navigator effectively creates and manages environments (and packages) using the conda utility. Navigator 使用 conda 实用程序有效地创建和管理环境(和包)。 It formulates and executes commands via conda, in a similar to how you execute conda commands on the Windows Console or Mac Terminal command line interface.它通过 conda 制定和执行命令,类似于您在 Windows 控制台或 Mac 终端命令行界面上执行 conda 命令的方式。

The Python package named "conda" provides a programmatic interface for calling conda functions from within Python programs.名为“conda”的 Python package 提供了一个编程接口,用于从 Python 程序中调用 conda 函数。

The "conda" command line utility is an environment manager; “conda”命令行实用程序是一个环境管理器; it is also a full package manager that does everything that the pip utility does.它也是一个完整的 package 管理器,可以执行 pip 实用程序所做的一切。

The "pip" command line utility is a package manager for Python-only packages in pip format. “pip”命令行实用程序是一个 package 管理器,用于 pip 格式的 Python 包。

The conda utility and conda package work in a language-agnostic way. conda 实用程序和 conda package 以 language-agnostic 的方式工作。 They can manage environments and packages for many other programming languages (eg, R, JavaScript, for starters) and many others.他们可以管理许多其他编程语言(例如,R、JavaScript,对于初学者)和许多其他语言的环境和包。

CONDA AT THE COMMAND LINE OR THROUGH THE NAVIGATOR?在命令行或通过导航器使用 CONDA?

You can use "conda" at the command line, OR you use the Navigator Environment and Package Manager GUI.您可以在命令行中使用“conda”,或者使用 Navigator Environment 和 Package Manager GUI。 I prefer the command line, because it is much faster and more precise.我更喜欢命令行,因为它更快更精确。

BE MINDFUL WHEN USING PIP AND CONDA TOGETHER:一起使用 PIP 和 CONDA 时请注意:

Be VERY careful about using pip and conda "side-by-side". “并排”使用 pip 和 conda 时要非常小心。 They each build and manage their own package indexes.他们各自建立和管理自己的 package 索引。 Interoperability is still an "experimental feature".互操作性仍然是一个“实验性功能”。 The best guide to pip and conda together is here: https://www.anaconda.com/blog/using-pip-in-a-conda-environment pip 和 conda 的最佳指南在这里: https://www.anaconda.com/blog/using-pip-in-a-conda-environment

One thing that I usually do is install the conda and pip packages into any new conda environment first (using "conda install -c conda-forge conda pip" at the command line).我通常做的一件事是首先将 conda 和 pip 软件包安装到任何新的 conda 环境中(在命令行中使用“conda install -c conda-forge conda pip”)。 After that conda then is informed about the pip package installations.之后,conda 会收到有关 pip package 安装的通知。 I find that pip corrupts my conda environments less frequently when I do this.当我这样做时,我发现 pip 破坏我的 conda 环境的频率较低。

See the following document for more information about using pip inside conda environments.有关在 conda 环境中使用 pip 的更多信息,请参阅以下文档。 https://docs.conda.io/projects/conda/en/stable/user-guide/configuration/pip-interoperability.html?highlight=pip https://docs.conda.io/projects/conda/en/stable/user-guide/configuration/pip-interoperability.html?highlight=pip

BOTTOM LINE: Take care using pip inside conda environments!底线:在 conda 环境中小心使用 pip!

ALWAYS LEAD WITH CONDA!始终以 CONDA 领先!

USE PIP LAST, after exhausting and using all available conda packages.使用 PIP LAST,在用尽并使用所有可用的 conda 包之后。

Do not keep interleaving conda and pip installation commands.不要交错使用 conda 和 pip 安装命令。

If you interleave conda and pip commands repeatedly in your Anaconda root or "base" environment, you will be eventually break your Anaconda installation, and must completely remove and re-install Anaconda.如果您在 Anaconda root 或“基本”环境中重复使用 conda 和 pip 命令,您最终将破坏 Anaconda 安装,并且必须完全删除并重新安装 Anaconda。

The Anaconda un-installation can be a dirty process on Windows and Mac, but luckily there are scripts to completely remove all traces of it, and then reinstall it. Anaconda 卸载在 Windows 和 Mac 上可能是一个肮脏的过程,但幸运的是有脚本可以完全删除它的所有痕迹,然后重新安装它。 [Uninstall Anaconda][4] [卸载 Anaconda][4]

[Conda User Manual][5] [康达用户手册][5]

[1]: https://carpentries-incubator.github.io/introduction-to-conda-for-data-scientists/04-sharing-environments/index.html#:~:text=Conda%20uses%20YAML%20(%E2%80%9CYAML%20Ain,style%20indentation%20to%20indicate%20nesting. [2]: Install only available packages using "conda install --yes --file requirements.txt" without error [3]: https://i.stack.imgur.com/5dHFL.png [4]: https://docs.anaconda.com/anaconda/install/uninstall/ [5]: https://docs.conda.io/projects/conda/en/stable/user-guide/index.html [1]: https://carpentries-incubator.github.io/introduction-to-conda-for-data-scientists/04-sharing-environments/index.html#:~:text=Conda%20uses%20YAML%20 (%E2%80%9CYAML%20Ain,style%20indentation%20to%20indicate%20nesting.[2]: 使用“conda install --yes --file requirements.txt”只安装可用的包没有错误[3]: https: //i.stack.imgur.com/5dHFL.png [4]: https://docs.anaconda.com/anaconda/install/uninstall/ [5]: https://docs.conda.io/projects/conda /zh/stable/user-guide/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用空闲的 python 将requirements.txt 中提到的所有 python 包下载到 linux 的文件夹中? - how to download all the python packages mentioned in the requirement.txt to a folder in linux using python idle? 如何使用python脚本安装Django项目requirements.txt - How can install Django project requirement.txt with python script 如何将required.txt中提到的所有python包下载到linux的文件夹中? - how to download all the python packages mentioned in the requirement.txt to a folder in linux? python中的Requirement.txt文件 - Requirement.txt file in python pipenv 如何决定我的 python 版本以及为什么生成的requirement.txt 与原始版本不同? - How does pipenv decide my python version and why does the requirement.txt generated different from the original? 在ubuntu上pip install -r requirements.txt - pip install -r requirement.txt on ubuntu 如何使用 pip 运行 requirements.txt 文件? - how to run requirement.txt file using pip? 如何从 requirements.txt 文件中选择特定版本 - how to pick a particular version from requirement.txt file 使用命令 pip install -r requirements.txt 安装要求时出现错误 - I am getting error while installing the requirements using the command pip install -r requirement.txt 从require.txt安装新软件包,而不升级已经满足的依赖关系 - Install a new package from requirement.txt without upgrading the dependencies which are already satisfied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM