当前位置: 首页 > 后端技术 > Python

再也不用为python环境发愁了-conda

时间:2023-03-25 21:00:59 Python

Conda攻略Conda简介conda是一个针对多种语言的包、依赖和环境管理工具,例如:Python,R,Scala,Java,Javascript,C/C++,语言。应用场景:比如在服务器A上开发了一个应用,安装了N个包。现在我们要迁移到服务器B,又得重新安装一遍。我们不知道服务器A上需要哪些包,conda通过将应用程序需要的包全部安装到应用程序所在的环境中来解决这个问题。迁移的时候只需要导出环境,然后导入到B环境即可。Conda的安装过程和windows的安装过程就不演示了。只需在网上搜索miniconda安装包,然后一路点击next即可完成安装。下面解释linux下的安装和创建condarc.mirror文件channels:-conda-forge-bioconda-defaultsshow_channel_urls:truedefault_channels:-https://mirrors.bfsu.edu.cn/anaconda/pkgs/main-https://mirrors.bfsu.edu.cn/anaconda/pkgs/r-https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2custom_channels:conda-forge:https://mirrors.bfsu.edu.cn/anaconda/cloudmsys2:https://mirrors.bfsu.edu.cn/anaconda/cloudbioconda:https://mirrors.bfsu.edu.cn/anaconda/cloudmenpo:https://mirrors.bfsu.edu.cn/anaconda/cloudpytorch:https://mirrors.bfsu.edu.cn/anaconda/cloudsimpleitk:https://mirrors.bfsu.edu.cn/anaconda/cloudcurl-L-o/tmp/miniconda.shhttps://repo.anaconda.com/miniconda/Miniconda3-py39_4.11.0-Linux-x86_64.sh/bin/bash/tmp/miniconda.sh-b-p/opt/condarm/tmp/miniconda.shcondaclean-tipsyfind/opt/conda-follow-typef-name'*.a'-deletefind/opt/conda-follow-typef-name'*.pyc'-deletecondaclean-afycp./condarc.mirror/root/.condarcupdatecondaconda更新teconda镜像服务器condaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/freecondaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forgecondaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/biocondacondaconfig--setshow_channel_urlsyes#执行以上命令后,会生成.condarc环境用户目录管理查看所有环境condaenvlistcreatenewenvironmentcondacreate--name[name]python_or_othersps:condacreate--nameFastAPIpython=3.9.12enterenvironmentcondaactivateenv_nameexitenvironmentcondadeactivatedeleteenvironmentcondaremove-nenv_name--allcopyEnvironmentcondacreate--cloneENVNAME--nameNEWENVpackagemanagementlistpackagecondalist列出指定环境中的所有包condalist-nmyenvinstallpackagepipinstallxxxx或condainstallxxxxps:pipinstalltensorflow如果你不't指定环境name带-n,安装在当前活动环境,也可以通过-c指定的通道安装condainstall(-npython34)numpy更新包condaupdate(-npython34)numpy卸载包condaremove/uninstallpackage_name查找包信息condasearch(-npython34)numpy更新当前环境下的所有包condaupdate--all导出当前环境的包信息condaenvexport>environment.yamlclearcachedeleteindexcache,lockfiles,未使用的缓存包和tarballs(压缩包).condaclean-aenvironmentcopy注意:yaml的方式很耗资源,系统配置至少要2核4G以上,yaml的包不能太多,否则会kill1,导出环境condaenvexport>environment.yaml文件内容示例名称:kylechannels:-https://mirrors.tuna。tsinghua.edu.cn/anaconda/cloud/conda-forge-https://repo.anaconda.com/pkgs/main-https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/-https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/-https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/-https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/-https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/-https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/-https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/-默认依赖项:-_pytorch_select=0.2=gpu_0-pip:-opencv-python==4.1.2.302.导入环境condaenvcreate-fenvironment.yaml3,克隆环境condaenvupdate-nmy_env--文件ENV.yaml