{"id":9346,"date":"2024-06-27T11:41:49","date_gmt":"2024-06-27T03:41:49","guid":{"rendered":"\/?p=9346"},"modified":"2024-06-27T11:41:49","modified_gmt":"2024-06-27T03:41:49","slug":"conda%e8%99%9a%e6%8b%9f%e7%8e%af%e5%a2%83%e7%9a%84%e5%a4%8d%e5%88%b6%e5%92%8c%e8%bf%81%e7%a7%bb","status":"publish","type":"post","link":"\/?p=9346","title":{"rendered":"Conda\u865a\u62df\u73af\u5883\u7684\u590d\u5236\u548c\u8fc1\u79fb"},"content":{"rendered":"<h3>\u5728\u672c\u673a\u590d\u5236Conda\u865a\u62df\u73af\u5883<\/h3>\n<pre><code>conda create --name \u65b0\u73af\u5883\u540d --clone \u65e7\u73af\u5883\u540d<\/code><\/pre>\n<h3>\u76f8\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u590d\u5236\u73af\u5883<\/h3>\n<h4>\u65b9\u6cd5\u4e00\uff1arequirements.txt<\/h4>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u63a8\u8350\uff0c\u56e0\u4e3a\u53ea\u4f1a\u5bfc\u51fa\u4f60\u4f7f\u7528pip\u5b89\u88c5\u7684\u4f9d\u8d56\u5305\uff0c\u4e0d\u4f1a\u5bfc\u51fa\u865a\u62df\u73af\u5883\u6240\u4f9d\u8d56\u7684\u5305\uff0c\u5e76\u4e0d\u9002\u7528\u4e8e\u865a\u62df\u73af\u5883\u7684\u8fc1\u79fb\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<p>\u4e8b\u5b9e\u4e0a\uff0c\u6b64\u65b9\u6cd5\u6bd4\u8f83\u9002\u7528\u4e8e\uff0c\u5df2\u7ecf\u660e\u786e\u77e5\u9053\u4f9d\u8d56\u54ea\u4e9b\u5305\uff0c\u6211\u4eec\u53ea\u9700\u8981package\u4fe1\u606f\u7684\u60c5\u51b5\uff0c\u5982\u5199\u9879\u76ee\u6587\u6863\uff0c\u544a\u8bc9\u522b\u4eba\u8fd0\u884c\u6211\u8fd9\u4e2a\u7cfb\u7edf\u5fc5\u987b\u5b89\u88c5\u54ea\u4e9b\u4f9d\u8d56\u5305\u3002\u800c\u5ffd\u7565\u865a\u62df\u73af\u5883\u672c\u8eab\u7684\u4f9d\u8d56\u73af\u5883\u3002<\/p>\n<pre><code>pip freeze &gt; requirements.txt  # \u751f\u6210requirements.txt\npip install -r requirements.txt  # \u4ecerequirements.txt\u5b89\u88c5\u4f9d\u8d56<\/code><\/pre>\n<h4>\u65b9\u6cd5\u4e8c : Environment.yml<\/h4>\n<p>\u8de8\u5e73\u53f0\u548c\u64cd\u4f5c\u7cfb\u7edf\u5171\u4eab\u9879\u76ee\u73af\u5883\u4e5f\u53ef\u4ee5\u4f7f\u7528 -export \u9009\u9879\u751f\u6210 environment.yml \u6587\u4ef6\u6765\u5b8c\u6210\u3002\u89c4\u8303\u5217\u8868\u548c environment.yml \u6587\u4ef6\u4e4b\u95f4\u7684\u533a\u522b\u5728\u4e8e environment.yml \u6587\u4ef6\u4e0d\u662f\u7279\u5b9a\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\uff0c\u800c\u662f\u4f7f\u7528 YAML \u683c\u5f0f\u5316\u7684\u3002\u53ea\u5217\u51fa\u5305\u540d\uff0cconda\u6839\u636e\u5305\u540d\u642d\u5efa\u73af\u5883\u3002\u53e6\u4e00\u4e2a\u533a\u522b\u662f -export \u8fd8\u5305\u62ec\u4f7f\u7528 pip \u5b89\u88c5\u7684\u5305\uff0c\u800c spec \u5217\u8868\u4e0d\u5305\u62ec\u3002\u8981\u5bfc\u51fa environment.yml \u6587\u4ef6\uff1a<\/p>\n<pre><code>conda env export environment.yml<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u8def\u5f84\u4e2d\u5df2\u6709 environment.yml \u6587\u4ef6\uff0cconda \u5c06\u8986\u76d6\u8be5\u6587\u4ef6\u3002\u521b\u5efa\u73af\u5883\uff1a<\/li>\n<\/ul>\n<pre><code>conda env create -f environment.yml<\/code><\/pre>\n<h4>\u65b9\u6cd5\u4e09\uff1aConda Pack<\/h4>\n<p>Conda-pack \u662f\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u4e8e\u6253\u5305 conda \u73af\u5883\uff0c\u5176\u4e2d\u5305\u62ec\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u5305\u7684\u6240\u6709\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u6b64\u6cd5\u652f\u6301\u65ad\u7f51\u73af\u5883\u4e0b\u4f7f\u7528\u3002Environment.yml \u662f\u4ecepython\u4f9d\u8d56\u5305\u5404\u81ea\u7684\u5b58\u50a8\u5e93\u4e2d\u4e0b\u8f7d\u5305\u6765\u521b\u5efa\u73af\u5883\uff0c\u7f3a\u70b9\u5f53\u7136\u662f\u7f51\u901f\u6162\u3001\u5bb9\u6613\u4e0b\u8f7d\u5931\u8d25\u7b49\u7b49\u3002\u6b64\u6cd5\u5c31\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u8bf7\u8bb0\u4f4f\uff0cconda-pack \u662f\u7279\u5b9a\u4e8e\u5e73\u53f0\u548c\u64cd\u4f5c\u7cfb\u7edf\u7684\uff0c\u76ee\u6807\u8ba1\u7b97\u673a\u5fc5\u987b\u5177\u6709\u4e0e\u6e90\u8ba1\u7b97\u673a\u76f8\u540c\u7684\u5e73\u53f0\u548c\u64cd\u4f5c\u7cfb\u7edf\u3002<br \/>\n\u8981\u5b89\u88c5 conda-pack\uff0c\u8bf7\u786e\u4fdd\u60a8\u5904\u4e8e root \u6216 base \u73af\u5883\u4e2d\uff0c\u4ee5\u4fbf\u5b83\u5728\u5b50\u73af\u5883\u4e2d\u53ef\u7528\u3002 Conda-pack \u53ef\u5728 conda-forge \u6216 PyPI \u83b7\u5f97\u3002<\/p>\n<p><strong>conda-forge:<\/strong><\/p>\n<pre><code>conda install -c conda-forge conda-pack<\/code><\/pre>\n<p><strong>PyPI:<\/strong><\/p>\n<pre><code>pip install conda-pack<\/code><\/pre>\n<h5>\u6253\u5305\u73af\u5883\uff1a<\/h5>\n<pre><code># Pack environment my_env into my_env.tar.gz\n$ conda pack -n my_env\n\n# Pack environment my_env into out_name.tar.gz\n$ conda pack -n my_env -o out_name.tar.gz\n\n# Pack environment located at an explicit path into my_env.tar.gz\n$ conda pack -p \/explicit\/path\/to\/my_env<\/code><\/pre>\n<h5>\u590d\u5236\u73af\u5883\u5230\u5176\u4ed6\u7535\u8111\u4e0a\uff1a<\/h5>\n<pre><code># Unpack environment into directory `my_env`\n$ mkdir -p my_env\n$ tar -xzf my_env.tar.gz -C my_env\n\n# Use Python without activating or fixing the prefixes. Most Python\n# libraries will work fine, but things that require prefix cleanups\n# will fail.\n$ .\/my_env\/bin\/python\n\n# Activate the environment. This adds `my_env\/bin` to your path\n$ source my_env\/bin\/activate\n\n# Run Python from in the environment\n(my_env) $ python\n\n# Cleanup prefixes from in the active environment.\n# Note that this command can also be run without activating the environment\n# as long as some version of Python is already installed on the machine.\n(my_env) $ conda-unpack<\/code><\/pre>\n<h4>\u65b9\u6cd5\u56db\uff1a\u76f4\u63a5\u590d\u5236envs\u76ee\u5f55\u4e0b\u7684\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939<\/h4>\n<p>\u5728\u65ad\u7f51\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4ece\u6e90\u7535\u8111\uff08\u4ee5\u4e0b\u7edf\u79f0\u4e3asrc\u7535\u8111\uff09\u4e0a\u76f4\u63a5\u5c06\u865a\u62df\u73af\u5883\u6574\u4e2a\u590d\u5236\u5230\u76ee\u6807\u7535\u8111\uff08\u4ee5\u4e0b\u7edf\u79f0\u4e3atarget\u7535\u8111\uff09\u4e0a\u3002\u524d\u63d0\u662ftarget\u8ba1\u7b97\u673a\u5fc5\u987b\u5177\u6709\u4e0esrc\u8ba1\u7b97\u673a\u76f8\u540c\u7684\u5e73\u53f0\u548c\u64cd\u4f5c\u7cfb\u7edf\u3002<\/p>\n<h5>1\u3001target\u7535\u8111\u4e0a\u5b89\u88c5\u76f8\u540c\u7248\u672c\u7684Anaconda\u3002<\/h5>\n<h5>2\u3001\u4ecesrc\u7535\u8111\u628aenvs\u6587\u4ef6\u5939\u4e2d\u9700\u8981\u590d\u5236\u7684\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939\u590d\u5236\u5230target\u7535\u8111\u4e0a\uff0c\u4f4d\u7f6e\u968f\u4fbf\u653e\u3002<\/h5>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u67e5\u770bsrc\u7535\u8111\u4e0a\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939\u7684\u5b58\u653e\u8def\u5f84\uff1a<\/p>\n<pre><code>conda env list<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/143663567c6e0d5417b336212842eadd.png\" alt=\"image-20230426143639701\" \/><\/p>\n<p>\u5df2\u4e0a\u56fe\u4e3a\u4f8b\uff0cE:\\ProgramData\\Anaconda\\envs\\new_name \u5c31\u662f\u865a\u62df\u73af\u5883new_name\u7684\u5b58\u50a8\u8def\u5f84\u3002\u6211\u4eec\u5c06\u5b83\u76f4\u63a5\u590d\u5236\u5230target\u7535\u8111\u4e0a\u5373\u53ef\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/57778fde196684229f855f58ddd1adc0.png\" alt=\"image-20230426143959988\" \/><\/p>\n<h5>3\u3001\u5728target\u7535\u8111\u4e0a\uff0c\u8fdb\u5165conda\u547d\u4ee4\u884c\uff0c\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/h5>\n<pre><code>conda config --add envs_dirs %\u590d\u5236\u5230target\u7535\u8111\u4e0a\u7684envs\u8def\u5f84%<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> \u8fd9\u91cc\u7684\u8def\u5f84\u662f\u76ee\u6807\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939\u7684\u4e0a\u7ea7\u76ee\u5f55\uff01<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<p>\u6211\u5c06\u4e0a\u56fe\u4e2d\u7684new_name\u590d\u5236\u5230\u4e86target\u7535\u8111\u4e0a\uff0c\u5e76\u91cd\u547d\u540d\u4e3a\uff1aenv_pybd\u3002\u8def\u5f84\u4e3aG:\\anoconda_envs\\env_pybd<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/eaec13bcb8450a96f1f98c9d9f67f88b.png\" alt=\"image-20230426152249543\" \/><\/p>\n<p>\u90a3\u4e48\u6211\u5e94\u8be5\u7528conda\u6267\u884c\u547d\u4ee4\uff1a<\/p>\n<pre><code>conda config --add envs_dirs G:\\anoconda_envs\\<\/code><\/pre>\n<p>\u8fd0\u884c\u6210\u529f\u540e\uff0c\u4f1a\u5f80 C:\\user%\u5f53\u524d\u7528\u6237\u540d%.condarc \u91cc\u9762\u6dfb\u52a0\u4e00\u6761envs_dirs\u8bb0\u5f55\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/f859b9f841e862d983b838fadf27d036.png\" alt=\"image-20230426152437166\" \/><\/p>\n<p>\u518d\u8fd0\u884c<\/p>\n<pre><code>conda env list<\/code><\/pre>\n<p>\u5c31\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u5df2\u7ecf\u590d\u5236\u6210\u529f\u4e86\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/618924105e36f518469574ff9665ced9.png\" alt=\"image-20230426152756755\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u672c\u673a\u590d\u5236Conda\u865a\u62df\u73af\u5883 conda create &#8211;name \u65b0\u73af\u5883\u540d &#8211;clone \u65e7\u73af\u5883\u540d \u76f8\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u590d\u5236\u73af\u5883 \u65b9\u6cd5   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[21],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9346"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9346"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9346\/revisions"}],"predecessor-version":[{"id":9347,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9346\/revisions\/9347"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9346"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}