【Trick】conda指令安装yml文件中的python依赖

2024-05-04 14:44

本文主要是介绍【Trick】conda指令安装yml文件中的python依赖,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

安装python依赖通常使用【pip】或【conda】指令,pip主要用于txt文件,conda主要用于yml文件。以下将给出其使用方法

pip

首先,创建一个YAML文件,列出python依赖项。

dependencies:- python=3.8- numpy- pandas- matplotlib

然后,打开终端,运行pip指令(假设文件名为requirements,实际应用时下列指令应该根据文件名进行修改)。

对于yml:

pip install -r requirements.yml

对于txt:

pip install -r requirements.txt

后续只需等待即可。 

conda

 首先,创建一个YAML文件,列出python依赖项。

channels:- defaults
dependencies:- python=3.8- numpy- pandas- matplotlib

然后,打开终端,运行conda指令(假设文件名为requirements,实际应用时下列指令应该根据文件名进行修改)。

对于yml:

conda env create -f requirements.yml

后续只需等待即可。 

实际案例

yml文件内容如下:

name: con_110
channels:- pytorch- defaults
dependencies:- _libgcc_mutex=0.1=main- _openmp_mutex=4.5=1_gnu- backcall=0.2.0=pyhd3eb1b0_0- blas=1.0=mkl- bzip2=1.0.8=h7b6447c_0- ca-certificates=2022.07.19=h06a4308_0- certifi=2022.9.24=py37h06a4308_0- cudatoolkit=11.3.1=h2bc3f7f_2- debugpy=1.5.1=py37h295c915_0- decorator=5.1.1=pyhd3eb1b0_0- entrypoints=0.4=py37h06a4308_0- faiss-gpu=1.7.2=py3.7_h28a55e0_0_cuda11.3- ffmpeg=4.3=hf484d3e_0- freetype=2.11.0=h70c0345_0- giflib=5.2.1=h7b6447c_0- gmp=6.2.1=h2531618_2- gnutls=3.6.15=he1e5248_0- intel-openmp=2021.4.0=h06a4308_3561- ipykernel=6.15.2=py37h06a4308_0- ipython=7.31.1=py37h06a4308_1- jedi=0.18.1=py37h06a4308_1- joblib=1.1.0=pyhd3eb1b0_0- jpeg=9d=h7f8727e_0- jupyter_client=7.1.2=pyhd3eb1b0_0- jupyter_core=4.11.1=py37h06a4308_0- lame=3.100=h7b6447c_0- lcms2=2.12=h3be6417_0- ld_impl_linux-64=2.35.1=h7274673_9- libfaiss=1.7.2=hfc2d529_0_cuda11.3- libffi=3.3=he6710b0_2- libgcc-ng=9.3.0=h5101ec6_17- libgfortran-ng=7.5.0=ha8ba4b0_17- libgfortran4=7.5.0=ha8ba4b0_17- libgomp=9.3.0=h5101ec6_17- libiconv=1.15=h63c8f33_5- libidn2=2.3.2=h7f8727e_0- libpng=1.6.37=hbc83047_0- libsodium=1.0.18=h7b6447c_0- libstdcxx-ng=9.3.0=hd4cf53a_17- libtasn1=4.16.0=h27cfd23_0- libtiff=4.2.0=h85742a9_0- libunistring=0.9.10=h27cfd23_0- libuv=1.40.0=h7b6447c_0- libwebp=1.2.2=h55f646e_0- libwebp-base=1.2.2=h7f8727e_0- lz4-c=1.9.3=h295c915_1- matplotlib-inline=0.1.6=py37h06a4308_0- mkl=2021.4.0=h06a4308_640- mkl-service=2.4.0=py37h7f8727e_0- mkl_fft=1.3.1=py37hd3c417c_0- mkl_random=1.2.2=py37h51133e4_0- ncurses=6.3=h7f8727e_2- nest-asyncio=1.5.5=py37h06a4308_0- nettle=3.7.3=hbbd107a_1- numpy=1.21.2=py37h20f2e39_0- numpy-base=1.21.2=py37h79a1101_0- olefile=0.46=py37_0- openh264=2.1.1=h4ff587b_0- openssl=1.1.1q=h7f8727e_0- packaging=21.3=pyhd3eb1b0_0- parso=0.8.3=pyhd3eb1b0_0- pexpect=4.8.0=pyhd3eb1b0_3- pickleshare=0.7.5=pyhd3eb1b0_1003- pillow=8.4.0=py37h5aabda8_0- pip=21.2.2=py37h06a4308_0- prompt-toolkit=3.0.20=pyhd3eb1b0_0- ptyprocess=0.7.0=pyhd3eb1b0_2- py=1.11.0=pyhd3eb1b0_0- pygments=2.11.2=pyhd3eb1b0_0- pyparsing=3.0.9=py37h06a4308_0- python=3.7.11=h12debd9_0- python-dateutil=2.8.2=pyhd3eb1b0_0- pytorch=1.10.2=py3.7_cuda11.3_cudnn8.2.0_0- pytorch-mutex=1.0=cuda- pyzmq=22.3.0=py37h295c915_2- readline=8.1.2=h7f8727e_1- scikit-learn=1.0.2=py37h51133e4_1- scipy=1.7.3=py37hc147768_0- setuptools=58.0.4=py37h06a4308_0- six=1.16.0=pyhd3eb1b0_1- sqlite=3.37.2=hc218d9a_0- threadpoolctl=2.2.0=pyh0d69192_0- tk=8.6.11=h1ccaba5_0- torchvision=0.11.3=py37_cu113- tornado=6.1=py37h27cfd23_0- tqdm=4.62.3=pyhd3eb1b0_1- traitlets=5.1.1=pyhd3eb1b0_0- typing_extensions=3.10.0.2=pyh06a4308_0- wcwidth=0.2.5=pyhd3eb1b0_0- wheel=0.37.1=pyhd3eb1b0_0- xz=5.2.5=h7b6447c_0- zeromq=4.3.4=h2531618_0- zlib=1.2.11=h7f8727e_4- zstd=1.4.9=haebb681_0- pip:- charset-normalizer==2.0.12- click==8.0.4- docker-pycreds==0.4.0- gitdb==4.0.9- gitpython==3.1.27- idna==3.3- importlib-metadata==4.11.1- pathtools==0.1.2- promise==2.3- protobuf==3.19.4- psutil==5.9.0- pyyaml==6.0- requests==2.27.1- sentry-sdk==1.5.6- shortuuid==1.0.8- smmap==5.0.0- termcolor==1.1.0- urllib3==1.26.8- wandb==0.12.10- yaspin==2.1.0- zipp==3.7.0

conda指令如下:

conda env create -f environment.yml

运行过程如下:

(base) ubuntu@xwk2:~/GG$ conda env create -f environment.yml
Retrieving notices: ...working... done
Collecting package metadata (repodata.json): - WARNING conda.models.version:get_matcher(556): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 1.7.1.*, but conda is ignoring the .* and treating it as 1.7.1
WARNING conda.models.version:get_matcher(556): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 1.9.0.*, but conda is ignoring the .* and treating it as 1.9.0
WARNING conda.models.version:get_matcher(556): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 1.8.0.*, but conda is ignoring the .* and treating it as 1.8.0
WARNING conda.models.version:get_matcher(556): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda. Your spec was 1.6.0.*, but conda is ignoring the .* and treating it as 1.6.0
done
Solving environment: done==> WARNING: A newer version of conda exists. <==current version: 23.7.3latest version: 24.4.0Please update conda by running$ conda update -n base -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main condaOr to minimize the number of packages updated during conda update useconda install conda=24.4.0Downloading and Extracting Packages
blas-1.0             | 6 KB      | ############################################################################## | 100% 
certifi-2022.9.24    | 154 KB    | ############################################################################## | 100% 
setuptools-58.0.4    | 775 KB    | ############################################################################## | 100% 
numpy-base-1.21.2    | 4.8 MB    | ############################################################################## | 100% 
ipykernel-6.15.2     | 189 KB    | ############################################################################## | 100% 
prompt-toolkit-3.0.2 | 259 KB    | ############################################################################## | 100% 
pygments-2.11.2      | 759 KB    | ############################################################################## | 100% 
python-3.7.11        | 45.3 MB   | ############################################################################## | 100% 
pyzmq-22.3.0         | 465 KB    | ############################################################################## | 100% 
libunistring-0.9.10  | 536 KB    | ############################################################################## | 100% 
entrypoints-0.4      | 16 KB     | ############################################################################## | 100% ... (more hidden) ...Preparing transaction: done                                                                                              
Verifying transaction: done                                                                                              
Executing transaction: \ By downloading and using the CUDA Toolkit conda packages, you accept the terms and conditions of the CUDA End User License Agreement (EULA): https://docs.nvidia.com/cuda/eula/index.html                                \                                                                                                                        Installed package of scikit-learn can be accelerated using scikit-learn-intelex.                                     More details are available here: https://intel.github.io/scikit-learn-intelex                                        For example:      $ conda install scikit-learn-intelex$ python -m sklearnex my_application.pydone
Installing pip dependencies: \ Ran pip subprocess with arguments:
['/home/ubuntu/miniconda3/envs/con_110/bin/python', '-m', 'pip', 'install', '-U', '-r', '/home/ubuntu/GLC/condaenv.h1f9e76a.requirements.txt', '--exists-action=b']
Pip subprocess output:
Collecting charset-normalizer==2.0.12Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Collecting click==8.0.4Downloading click-8.0.4-py3-none-any.whl (97 kB)
Collecting docker-pycreds==0.4.0Downloading docker_pycreds-0.4.0-py2.py3-none-any.whl (9.0 kB)
Collecting gitdb==4.0.9Downloading gitdb-4.0.9-py3-none-any.whl (63 kB)
Collecting gitpython==3.1.27Downloading GitPython-3.1.27-py3-none-any.whl (181 kB)
Collecting idna==3.3Downloading idna-3.3-py3-none-any.whl (61 kB)
Collecting importlib-metadata==4.11.1Downloading importlib_metadata-4.11.1-py3-none-any.whl (17 kB)
Collecting pathtools==0.1.2Downloading pathtools-0.1.2.tar.gz (11 kB)
Collecting promise==2.3Downloading promise-2.3.tar.gz (19 kB)
Collecting protobuf==3.19.4Downloading protobuf-3.19.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB)
Collecting psutil==5.9.0Downloading psutil-5.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (280 kB)
Collecting pyyaml==6.0Downloading PyYAML-6.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (596 kB)
Collecting requests==2.27.1Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
Collecting sentry-sdk==1.5.6Downloading sentry_sdk-1.5.6-py2.py3-none-any.whl (144 kB)
Collecting shortuuid==1.0.8Downloading shortuuid-1.0.8-py3-none-any.whl (9.5 kB)
Collecting smmap==5.0.0Downloading smmap-5.0.0-py3-none-any.whl (24 kB)
Collecting termcolor==1.1.0Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Collecting urllib3==1.26.8Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
Collecting wandb==0.12.10Downloading wandb-0.12.10-py2.py3-none-any.whl (1.7 MB)
Collecting yaspin==2.1.0Downloading yaspin-2.1.0-py3-none-any.whl (18 kB)
Collecting zipp==3.7.0Downloading zipp-3.7.0-py3-none-any.whl (5.3 kB)
Requirement already satisfied: six>=1.4.0 in /home/ubuntu/miniconda3/envs/con_110/lib/python3.7/site-packages (from docker-pycreds==0.4.0->-r /home/ubuntu/GLC/condaenv.h1f9e76a.requirements.txt (line 3)) (1.16.0)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/ubuntu/miniconda3/envs/con_110/lib/python3.7/site-packages (from gitpython==3.1.27->-r /home/ubuntu/GLC/condaenv.h1f9e76a.requirements.txt (line 5)) (3.10.0.2)
Requirement already satisfied: certifi>=2017.4.17 in /home/ubuntu/miniconda3/envs/con_110/lib/python3.7/site-packages (from requests==2.27.1->-r /home/ubuntu/GLC/condaenv.h1f9e76a.requirements.txt (line 13)) (2022.9.24)
Requirement already satisfied: python-dateutil>=2.6.1 in /home/ubuntu/miniconda3/envs/con_110/lib/python3.7/site-packages (from wandb==0.12.10->-r /home/ubuntu/GLC/condaenv.h1f9e76a.requirements.txt (line 19)) (2.8.2)
Building wheels for collected packages: pathtools, promise, termcolorBuilding wheel for pathtools (setup.py): startedBuilding wheel for pathtools (setup.py): finished with status 'done'Created wheel for pathtools: filename=pathtools-0.1.2-py3-none-any.whl size=8806 sha256=a66ada93957cf7fc7b3ef5bffd7844b018a4a97eaca9289f2e292761489ee2d8Stored in directory: /home/ubuntu/.cache/pip/wheels/3e/31/09/fa59cef12cdcfecc627b3d24273699f390e71828921b2cbba2Building wheel for promise (setup.py): startedBuilding wheel for promise (setup.py): finished with status 'done'Created wheel for promise: filename=promise-2.3-py3-none-any.whl size=21503 sha256=884eb51f491d088c5fb1959e5be5f3ec41086ef58eac9c32cc737c5c83a45578Stored in directory: /home/ubuntu/.cache/pip/wheels/29/93/c6/762e359f8cb6a5b69c72235d798804cae523bbe41c2aa8333dBuilding wheel for termcolor (setup.py): startedBuilding wheel for termcolor (setup.py): finished with status 'done'Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4848 sha256=889e55b1d10f55c622c011af4442358d02ae5abd2629c38ed91bdaebd3dd542dStored in directory: /home/ubuntu/.cache/pip/wheels/3f/e3/ec/8a8336ff196023622fbcb36de0c5a5c218cbb24111d1d4c7f2
Successfully built pathtools promise termcolor
Installing collected packages: zipp, smmap, urllib3, termcolor, importlib-metadata, idna, gitdb, charset-normalizer, yaspin, shortuuid, sentry-sdk, requests, pyyaml, psutil, protobuf, promise, pathtools, gitpython, docker-pycreds, click, wandbAttempting uninstall: psutilFound existing installation: psutil 5.8.0Uninstalling psutil-5.8.0:Successfully uninstalled psutil-5.8.0
Successfully installed charset-normalizer-2.0.12 click-8.0.4 docker-pycreds-0.4.0 gitdb-4.0.9 gitpython-3.1.27 idna-3.3 importlib-metadata-4.11.1 pathtools-0.1.2 promise-2.3 protobuf-3.19.4 psutil-5.9.0 pyyaml-6.0 requests-2.27.1 sentry-sdk-1.5.6 shortuuid-1.0.8 smmap-5.0.0 termcolor-1.1.0 urllib3-1.26.8 wandb-0.12.10 yaspin-2.1.0 zipp-3.7.0done
#
# To activate this environment, use
#
#     $ conda activate con_110
#
# To deactivate an active environment, use
#
#     $ conda deactivate

这篇关于【Trick】conda指令安装yml文件中的python依赖的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/959447

相关文章

Python脚本实现自动删除C盘临时文件夹

《Python脚本实现自动删除C盘临时文件夹》在日常使用电脑的过程中,临时文件夹往往会积累大量的无用数据,占用宝贵的磁盘空间,下面我们就来看看Python如何通过脚本实现自动删除C盘临时文件夹吧... 目录一、准备工作二、python脚本编写三、脚本解析四、运行脚本五、案例演示六、注意事项七、总结在日常使用

Python将大量遥感数据的值缩放指定倍数的方法(推荐)

《Python将大量遥感数据的值缩放指定倍数的方法(推荐)》本文介绍基于Python中的gdal模块,批量读取大量多波段遥感影像文件,分别对各波段数据加以数值处理,并将所得处理后数据保存为新的遥感影像... 本文介绍基于python中的gdal模块,批量读取大量多波段遥感影像文件,分别对各波段数据加以数值处

python管理工具之conda安装部署及使用详解

《python管理工具之conda安装部署及使用详解》这篇文章详细介绍了如何安装和使用conda来管理Python环境,它涵盖了从安装部署、镜像源配置到具体的conda使用方法,包括创建、激活、安装包... 目录pytpshheraerUhon管理工具:conda部署+使用一、安装部署1、 下载2、 安装3

Python进阶之Excel基本操作介绍

《Python进阶之Excel基本操作介绍》在现实中,很多工作都需要与数据打交道,Excel作为常用的数据处理工具,一直备受人们的青睐,本文主要为大家介绍了一些Python中Excel的基本操作,希望... 目录概述写入使用 xlwt使用 XlsxWriter读取修改概述在现实中,很多工作都需要与数据打交

使用Python实现在Word中添加或删除超链接

《使用Python实现在Word中添加或删除超链接》在Word文档中,超链接是一种将文本或图像连接到其他文档、网页或同一文档中不同部分的功能,本文将为大家介绍一下Python如何实现在Word中添加或... 在Word文档中,超链接是一种将文本或图像连接到其他文档、网页或同一文档中不同部分的功能。通过添加超

JAVA系统中Spring Boot应用程序的配置文件application.yml使用详解

《JAVA系统中SpringBoot应用程序的配置文件application.yml使用详解》:本文主要介绍JAVA系统中SpringBoot应用程序的配置文件application.yml的... 目录文件路径文件内容解释1. Server 配置2. Spring 配置3. Logging 配置4. Ma

Python MySQL如何通过Binlog获取变更记录恢复数据

《PythonMySQL如何通过Binlog获取变更记录恢复数据》本文介绍了如何使用Python和pymysqlreplication库通过MySQL的二进制日志(Binlog)获取数据库的变更记录... 目录python mysql通过Binlog获取变更记录恢复数据1.安装pymysqlreplicat

利用Python编写一个简单的聊天机器人

《利用Python编写一个简单的聊天机器人》这篇文章主要为大家详细介绍了如何利用Python编写一个简单的聊天机器人,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 使用 python 编写一个简单的聊天机器人可以从最基础的逻辑开始,然后逐步加入更复杂的功能。这里我们将先实现一个简单的

基于Python开发电脑定时关机工具

《基于Python开发电脑定时关机工具》这篇文章主要为大家详细介绍了如何基于Python开发一个电脑定时关机工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 简介2. 运行效果3. 相关源码1. 简介这个程序就像一个“忠实的管家”,帮你按时关掉电脑,而且全程不需要你多做

Python实现高效地读写大型文件

《Python实现高效地读写大型文件》Python如何读写的是大型文件,有没有什么方法来提高效率呢,这篇文章就来和大家聊聊如何在Python中高效地读写大型文件,需要的可以了解下... 目录一、逐行读取大型文件二、分块读取大型文件三、使用 mmap 模块进行内存映射文件操作(适用于大文件)四、使用 pand