[英]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 中的所有软件包感到困惑。
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.在这个领域有大量不同的术语和语义。
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.