本文主要是介绍【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依赖的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!