{"id":1089198,"date":"2025-01-08T13:51:27","date_gmt":"2025-01-08T05:51:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1089198.html"},"modified":"2025-01-08T13:51:29","modified_gmt":"2025-01-08T05:51:29","slug":"%e5%a6%82%e4%bd%95%e5%b0%86python%e7%a7%bb%e5%88%b0u%e7%9b%98%e4%b8%ad-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1089198.html","title":{"rendered":"\u5982\u4f55\u5c06python\u79fb\u5230u\u76d8\u4e2d"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202224\/0438f9c5-21dc-42fd-9b85-962d1a1809ec.webp\" alt=\"\u5982\u4f55\u5c06python\u79fb\u5230u\u76d8\u4e2d\" \/><\/p>\n<p><p> <strong>\u5c06Python\u79fb\u5230U\u76d8\u4e2d\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4fbf\u643a\u7248Python\u3001\u5728U\u76d8\u4e2d\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u590d\u5236\u9879\u76ee\u6587\u4ef6\u5230U\u76d8\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u5e93\u3001\u6d4b\u8bd5Python\u73af\u5883<\/strong>\uff0c\u5176\u4e2d\u8be6\u7ec6\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4fbf\u643a\u7248Python<\/h2>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4e3a\u4e86\u5c06Python\u79fb\u5230U\u76d8\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u4e0b\u8f7d\u4e00\u4e2a\u4fbf\u643a\u7248\uff08portable\uff09Python\u3002\u4fbf\u643a\u7248Python\u662f\u4e13\u95e8\u8bbe\u8ba1\u4e3a\u53ef\u4ee5\u5728\u4e0d\u540c\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u800c\u4e0d\u9700\u8981\u8fdb\u884c\u4efb\u4f55\u7cfb\u7edf\u7ea7\u5b89\u88c5\u7684\u7248\u672c\u3002\u4f60\u53ef\u4ee5\u4ece\u4e00\u4e9b\u77e5\u540d\u7684\u5f00\u6e90\u9879\u76ee\u5982 Portable Python \u6216 WinPython \u4e0b\u8f7d\u4fbf\u643a\u7248Python\u3002\u4e0b\u8f7d\u540e\uff0c\u53ea\u9700\u5c06\u5176\u89e3\u538b\u5230U\u76d8\u4e2d\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u5728U\u76d8\u4e2d\u521b\u5efa\u865a\u62df\u73af\u5883<\/h2>\n<\/p>\n<p><p>\u5728U\u76d8\u4e2d\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\u662f\u4e3a\u4e86\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u548c\u4f9d\u8d56\u5e93\u90fd\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e0a\u72ec\u7acb\u8fd0\u884c\u3002\u8fdb\u5165\u4fbf\u643a\u7248Python\u7684\u76ee\u5f55\uff0c\u6253\u5f00\u547d\u4ee4\u884c\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4f1a\u5728U\u76d8\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmyenv\u201d\u7684\u865a\u62df\u73af\u5883\u3002\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u65b9\u6cd5\u56e0\u64cd\u4f5c\u7cfb\u7edf\u800c\u5f02\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u590d\u5236\u9879\u76ee\u6587\u4ef6\u5230U\u76d8<\/h2>\n<\/p>\n<p><p>\u5c06\u4f60\u9700\u8981\u8fd0\u884c\u7684Python\u9879\u76ee\u6587\u4ef6\u590d\u5236\u5230U\u76d8\u4e2d\u7684\u67d0\u4e2a\u76ee\u5f55\u3002\u786e\u4fdd\u6240\u6709\u7684\u811a\u672c\u6587\u4ef6\u3001\u914d\u7f6e\u6587\u4ef6\u548c\u6570\u636e\u6587\u4ef6\u90fd\u88ab\u5b8c\u6574\u5730\u590d\u5236\u5230U\u76d8\u4e2d\uff0c\u4ee5\u4fdd\u8bc1\u9879\u76ee\u80fd\u591f\u6b63\u786e\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u5e93<\/h2>\n<\/p>\n<p><p>\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u4f7f\u7528pip\u5b89\u88c5\u4f60\u7684\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u4f9d\u8d56\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>requirements.txt<\/code>\u6587\u4ef6\u5e94\u8be5\u5305\u542b\u4f60\u9879\u76ee\u6240\u9700\u7684\u6240\u6709Python\u5305\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u6d4b\u8bd5Python\u73af\u5883<\/h2>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e\uff0c\u4f60\u9700\u8981\u6d4b\u8bd5\u4e00\u4e0b\u6574\u4e2aPython\u73af\u5883\u662f\u5426\u80fd\u5728\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e0a\u6b63\u5e38\u8fd0\u884c\u3002\u8fde\u63a5U\u76d8\u5230\u53e6\u4e00\u53f0\u8ba1\u7b97\u673a\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u5e76\u5c1d\u8bd5\u8fd0\u884c\u4f60\u7684Python\u9879\u76ee\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u606d\u559c\u4f60\uff0cPython\u5df2\u7ecf\u6210\u529f\u79fb\u5230U\u76d8\u4e2d\uff0c\u5e76\u53ef\u4ee5\u5728\u4e0d\u540c\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u8be6\u7ec6\u6b65\u9aa4\u89e3\u6790<\/h3>\n<\/p>\n<p><h4>\u4e00\u3001\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4fbf\u643a\u7248Python<\/h4>\n<\/p>\n<p><h2><strong>\u4fbf\u643a\u7248Python\u7684\u9009\u62e9<\/strong><\/h2>\n<\/p>\n<p><p>\u4fbf\u643a\u7248Python\u80fd\u591f\u8ba9\u4f60\u5728\u4e0d\u8fdb\u884c\u590d\u6742\u5b89\u88c5\u7684\u60c5\u51b5\u4e0b\uff0c\u5728\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u63a8\u8350\u7684\u4fbf\u643a\u7248Python\u6709Portable Python\u548cWinPython\u3002\u4f60\u53ef\u4ee5\u4ece\u5b83\u4eec\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5230\u6700\u65b0\u7684\u4fbf\u643a\u7248Python\u3002<\/p>\n<\/p>\n<p><h2><strong>\u5b89\u88c5\u4fbf\u643a\u7248Python<\/strong><\/h2>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u89e3\u538b\u7f29\u6587\u4ef6\u5939\u5230U\u76d8\u7684\u6839\u76ee\u5f55\u4e2d\u3002\u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\uff0c\u53ef\u4ee5\u5c06\u89e3\u538b\u540e\u7684\u6587\u4ef6\u5939\u91cd\u547d\u540d\u4e3a\u201cPortablePython\u201d\u3002\u4fbf\u643a\u7248Python\u5305\u542b\u4e86\u57fa\u672c\u7684Python\u89e3\u91ca\u5668\u548c\u4e00\u4e9b\u5e38\u7528\u7684\u5de5\u5177\uff0c\u4f8b\u5982pip\u3002<\/p>\n<\/p>\n<p><h4>\u4e8c\u3001\u5728U\u76d8\u4e2d\u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><h2><strong>\u865a\u62df\u73af\u5883\u7684\u91cd\u8981\u6027<\/strong><\/h2>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5728\u9879\u76ee\u4e4b\u95f4\u9694\u79bbPython\u5305\u548c\u5e93\uff0c\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002\u5c24\u5176\u662f\u5728\u4fbf\u643a\u5f0f\u73af\u5883\u4e2d\uff0c\u865a\u62df\u73af\u5883\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u5728\u4efb\u4f55\u8ba1\u7b97\u673a\u4e0a\u90fd\u80fd\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h2><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/h2>\n<\/p>\n<p><p>\u6253\u5f00U\u76d8\u4e2d\u7684\u4fbf\u643a\u7248Python\u76ee\u5f55\uff0c\u542f\u52a8\u547d\u4ee4\u884c\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6761\u547d\u4ee4\u5c06\u5728U\u76d8\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmyenv\u201d\u7684\u865a\u62df\u73af\u5883\u3002\u4e3a\u4e86\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff08\u5047\u8bbe\u4f60\u4f7f\u7528\u7684\u662fWindows\u7cfb\u7edf\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bf9\u4e8eLinux\u6216MacOS\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4e09\u3001\u590d\u5236\u9879\u76ee\u6587\u4ef6\u5230U\u76d8<\/h4>\n<\/p>\n<p><h2><strong>\u51c6\u5907\u9879\u76ee\u6587\u4ef6<\/strong><\/h2>\n<\/p>\n<p><p>\u4f60\u9700\u8981\u786e\u4fdd\u6240\u6709\u7684Python\u811a\u672c\u3001\u914d\u7f6e\u6587\u4ef6\u3001\u6570\u636e\u6587\u4ef6\u548c\u5176\u4ed6\u76f8\u5173\u6587\u4ef6\u90fd\u88ab\u6b63\u786e\u590d\u5236\u5230U\u76d8\u4e2d\u3002\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u7684\u76ee\u5f55\u6765\u5b58\u653e\u8fd9\u4e9b\u6587\u4ef6\uff0c\u4f8b\u5982\u201c\/Projects\/MyPythonProject\u201d\u3002<\/p>\n<\/p>\n<p><h2><strong>\u590d\u5236\u6587\u4ef6<\/strong><\/h2>\n<\/p>\n<p><p>\u5c06\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u590d\u5236\u5230\u4e0a\u8ff0\u76ee\u5f55\u4e2d\u3002\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u7684\u6587\u4ef6\u548c\u6570\u636e\u90fd\u88ab\u5b8c\u6574\u590d\u5236\uff0c\u4ee5\u514d\u5728\u8fd0\u884c\u65f6\u51fa\u73b0\u7f3a\u5c11\u6587\u4ef6\u7684\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>\u56db\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u5e93<\/h4>\n<\/p>\n<p><h2><strong>\u5b89\u88c5\u4f9d\u8d56\u5e93<\/strong><\/h2>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u6fc0\u6d3b\u72b6\u6001\u4e0b\uff0c\u4f7f\u7528pip\u5b89\u88c5\u4f60\u7684\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u5e93\u3002\u9996\u5148\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e2d\u6709\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542b\u4e86\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5e93\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u8fd9\u4e9b\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u6ca1\u6709<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u53ef\u4ee5\u624b\u52a8\u5b89\u88c5\u6bcf\u4e2a\u4f9d\u8d56\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install library_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4e94\u3001\u6d4b\u8bd5Python\u73af\u5883<\/h4>\n<\/p>\n<p><h2><strong>\u6d4b\u8bd5\u73af\u5883<\/strong><\/h2>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u6240\u6709\u6b65\u9aa4\u540e\uff0c\u6700\u540e\u4e00\u6b65\u662f\u6d4b\u8bd5\u4f60\u7684Python\u73af\u5883\u3002\u5728U\u76d8\u8fde\u63a5\u5230\u53e6\u4e00\u53f0\u8ba1\u7b97\u673a\u540e\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u5e76\u5c1d\u8bd5\u8fd0\u884c\u4f60\u7684Python\u9879\u76ee\u3002\u786e\u4fdd\u6240\u6709\u529f\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u5e76\u4e14\u6ca1\u6709\u4f9d\u8d56\u5e93\u6216\u6587\u4ef6\u7f3a\u5931\u3002<\/p>\n<\/p>\n<p><h2><strong>\u793a\u4f8b\u6d4b\u8bd5<\/strong><\/h2>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u811a\u672c\uff0c\u786e\u4fdd\u6240\u6709\u4e3b\u8981\u529f\u80fd\u90fd\u80fd\u6b63\u5e38\u5de5\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import sys<\/p>\n<p>print(&quot;Python version:&quot;)<\/p>\n<p>print(sys.version)<\/p>\n<p>print(&quot;Current directory:&quot;)<\/p>\n<p>print(os.getcwd())<\/p>\n<p>print(&quot;List of files in the current directory:&quot;)<\/p>\n<p>print(os.listdir(&quot;.&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u4e0a\u8ff0\u811a\u672c\uff0c\u68c0\u67e5\u8f93\u51fa\u7ed3\u679c\u662f\u5426\u7b26\u5408\u9884\u671f\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u8bf4\u660e\u4f60\u7684Python\u73af\u5883\u5df2\u7ecf\u6210\u529f\u79fb\u5230\u4e86U\u76d8\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><h2><strong>\u95ee\u98981\uff1a\u865a\u62df\u73af\u5883\u65e0\u6cd5\u6fc0\u6d3b<\/strong><\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u65f6\u9047\u5230\u95ee\u9898\uff0c\u9996\u5148\u68c0\u67e5\u662f\u5426\u4f7f\u7528\u4e86\u6b63\u786e\u7684\u547d\u4ee4\u3002Windows\u7528\u6237\u5e94\u4f7f\u7528<code>myenv\\Scripts\\activate<\/code>\uff0c\u800cLinux\u6216MacOS\u7528\u6237\u5e94\u4f7f\u7528<code>source myenv\/bin\/activate<\/code>\u3002\u786e\u4fdd\u547d\u4ee4\u884c\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939\u5b58\u5728\u3002<\/p>\n<\/p>\n<p><h2><strong>\u95ee\u98982\uff1a\u4f9d\u8d56\u5e93\u5b89\u88c5\u5931\u8d25<\/strong><\/h2>\n<\/p>\n<p><p>\u5982\u679c\u5728\u5b89\u88c5\u4f9d\u8d56\u5e93\u65f6\u9047\u5230\u95ee\u9898\uff0c\u68c0\u67e5\u662f\u5426\u6b63\u786e\u914d\u7f6e\u4e86pip\u3002\u786e\u4fddU\u76d8\u4e2d\u7684Python\u89e3\u91ca\u5668\u80fd\u591f\u8bbf\u95ee\u4e92\u8054\u7f51\u3002\u5982\u679c\u662f\u7f51\u7edc\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u79bb\u7ebf\u5305\u5b89\u88c5\u6216\u9009\u62e9\u5176\u4ed6\u955c\u50cf\u6e90\u3002<\/p>\n<\/p>\n<p><h2><strong>\u95ee\u98983\uff1a\u9879\u76ee\u6587\u4ef6\u7f3a\u5931<\/strong><\/h2>\n<\/p>\n<p><p>\u786e\u4fdd\u6240\u6709\u9879\u76ee\u6587\u4ef6\u90fd\u88ab\u5b8c\u6574\u590d\u5236\u5230U\u76d8\u4e2d\u3002\u68c0\u67e5\u76ee\u5f55\u7ed3\u6784\u662f\u5426\u6b63\u786e\uff0c\u914d\u7f6e\u6587\u4ef6\u548c\u6570\u636e\u6587\u4ef6\u662f\u5426\u5b8c\u6574\u3002\u5982\u679c\u9879\u76ee\u6587\u4ef6\u8fc7\u591a\uff0c\u53ef\u4ee5\u4f7f\u7528\u6587\u4ef6\u540c\u6b65\u5de5\u5177\u6765\u786e\u4fdd\u6587\u4ef6\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u8fdb\u9636\u4f7f\u7528<\/h3>\n<\/p>\n<p><h2><strong>\u591a<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a><\/strong><\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u6709\u591a\u4e2aPython\u9879\u76ee\u9700\u8981\u5728\u4e0d\u540c\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\uff0c\u53ef\u4ee5\u5728U\u76d8\u4e2d\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u5355\u72ec\u7684\u865a\u62df\u73af\u5883\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv project1_env<\/p>\n<p>python -m venv project2_env<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6bcf\u4e2a\u9879\u76ee\u90fd\u6709\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270\u3002<\/p>\n<\/p>\n<p><h2><strong>\u81ea\u52a8\u5316\u811a\u672c<\/strong><\/h2>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u81ea\u52a8\u5316\u811a\u672c\uff0c\u7528\u4e8e\u4e00\u952e\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u5e76\u8fd0\u884c\u9879\u76ee\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">@echo off<\/p>\n<p>set MY_ENV=myenv\\Scripts\\activate<\/p>\n<p>call %MY_ENV%<\/p>\n<p>python my_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u4e0a\u8ff0\u811a\u672c\u4fdd\u5b58\u4e3a<code>run_project.bat<\/code>\uff0c\u653e\u7f6e\u5728U\u76d8\u6839\u76ee\u5f55\u3002\u53cc\u51fb\u8fd0\u884c\u811a\u672c\u5373\u53ef\u81ea\u52a8\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u5e76\u8fd0\u884c\u9879\u76ee\u3002<\/p>\n<\/p>\n<p><h2><strong>\u4fbf\u643a\u5f00\u53d1\u73af\u5883<\/strong><\/h2>\n<\/p>\n<p><p>\u9664\u4e86Python\u89e3\u91ca\u5668\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5728U\u76d8\u4e2d\u5b89\u88c5\u4e00\u4e2a\u4fbf\u643a\u7248\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u4f8b\u5982Visual Studio Code Portable\u6216Sublime Text Portable\u3002\u8fd9\u5c06\u4f7f\u4f60\u80fd\u591f\u5728\u4efb\u4f55\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5f00\u53d1\uff0c\u65e0\u9700\u5b89\u88c5\u989d\u5916\u7684\u8f6f\u4ef6\u3002<\/p>\n<\/p>\n<p><h2><strong>\u7248\u672c\u63a7\u5236<\/strong><\/h2>\n<\/p>\n<p><p>\u4f7f\u7528Git\u8fdb\u884c\u7248\u672c\u63a7\u5236\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\u3002\u4f60\u53ef\u4ee5\u5728U\u76d8\u4e2d\u5b89\u88c5\u4fbf\u643a\u7248\u7684Git\uff0c\u5e76\u5c06\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u521d\u59cb\u5316\u4e3aGit\u4ed3\u5e93\u3002\u8fd9\u5c06\u4f7f\u4f60\u80fd\u591f\u5728\u4e0d\u540c\u8ba1\u7b97\u673a\u4e4b\u95f4\u8f7b\u677e\u540c\u6b65\u4ee3\u7801\u548c\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u5b89\u5168\u6027\u4e0e\u5907\u4efd<\/h3>\n<\/p>\n<p><h2><strong>\u6570\u636e\u5b89\u5168<\/strong><\/h2>\n<\/p>\n<p><p>\u786e\u4fddU\u76d8\u4e2d\u7684\u6570\u636e\u5b89\u5168\u975e\u5e38\u91cd\u8981\u3002\u53ef\u4ee5\u4f7f\u7528\u6587\u4ef6\u52a0\u5bc6\u5de5\u5177\u52a0\u5bc6\u654f\u611f\u6570\u636e\uff0c\u6216\u4f7f\u7528\u5bc6\u7801\u4fdd\u62a4U\u76d8\u3002\u5b9a\u671f\u5907\u4efdU\u76d8\u4e2d\u7684\u91cd\u8981\u6587\u4ef6\uff0c\u4ee5\u9632\u6570\u636e\u4e22\u5931\u3002<\/p>\n<\/p>\n<p><h2><strong>\u5907\u4efd\u7b56\u7565<\/strong><\/h2>\n<\/p>\n<p><p>\u5b9a\u671f\u5c06U\u76d8\u4e2d\u7684\u6587\u4ef6\u5907\u4efd\u5230\u4e91\u5b58\u50a8\u6216\u5176\u4ed6\u5b89\u5168\u4f4d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u81ea\u52a8\u5316\u5907\u4efd\u5de5\u5177\u5b9e\u73b0\u5b9a\u671f\u5907\u4efd\uff0c\u786e\u4fdd\u6570\u636e\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n<\/p>\n<p><h2><strong>\u591a\u91cd\u5907\u4efd<\/strong><\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4e91\u5b58\u50a8\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7269\u7406\u5b58\u50a8\u8bbe\u5907\uff0c\u5982\u5916\u90e8\u786c\u76d8\u6216\u53e6\u4e00U\u76d8\uff0c\u8fdb\u884c\u591a\u91cd\u5907\u4efd\u3002\u8fd9\u5c06\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<p><h2><strong>\u603b\u7ed3<\/strong><\/h2>\n<\/p>\n<p><p>\u5c06Python\u79fb\u5230U\u76d8\u4e2d\u5e76\u5728\u4e0d\u540c\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u662f\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684\u6280\u80fd\u3002\u901a\u8fc7\u4e0b\u8f7d\u4fbf\u643a\u7248Python\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u590d\u5236\u9879\u76ee\u6587\u4ef6\u3001\u5b89\u88c5\u4f9d\u8d56\u5e93\u548c\u6d4b\u8bd5\u73af\u5883\uff0c\u4f60\u53ef\u4ee5\u5728\u4efb\u4f55\u8ba1\u7b97\u673a\u4e0a\u8f7b\u677e\u8fd0\u884c\u4f60\u7684Python\u9879\u76ee\u3002\u786e\u4fdd\u6570\u636e\u5b89\u5168\u548c\u5b9a\u671f\u5907\u4efd\u5c06\u8fdb\u4e00\u6b65\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u9760\u6027\u548c\u53ef\u7528\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728U\u76d8\u4e0a\u5b89\u88c5Python\u5e76\u786e\u4fdd\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\uff1f<\/strong><br \/>\u8981\u5728U\u76d8\u4e0a\u5b89\u88c5Python\uff0c\u60a8\u9700\u8981\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u5b89\u88c5\u5305\u3002\u5efa\u8bae\u4f7f\u7528\u4fbf\u643a\u7248Python\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u590d\u6742\u7684\u5b89\u88c5\u8fc7\u7a0b\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u5c06\u5176\u89e3\u538b\u7f29\u5230U\u76d8\u7684\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\u3002\u786e\u4fdd\u5728U\u76d8\u4e2d\u5305\u542bPython\u7684\u53ef\u6267\u884c\u6587\u4ef6\u548c\u76f8\u5173\u5e93\u3002\u63a5\u7740\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u8bbe\u7f6eU\u76d8\u8def\u5f84\uff0c\u4ece\u800c\u76f4\u63a5\u8fd0\u884cU\u76d8\u4e2d\u7684Python\u3002<\/p>\n<p><strong>\u5728U\u76d8\u4e2d\u8fd0\u884cPython\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728U\u76d8\u4e2d\u8fd0\u884cPython\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u51e0\u4e2a\u5173\u952e\u70b9\u3002\u9996\u5148\uff0c\u786e\u4fddU\u76d8\u5728\u4e0d\u540c\u8ba1\u7b97\u673a\u4e0a\u90fd\u80fd\u88ab\u8bc6\u522b\uff0c\u5176\u6b21\uff0cU\u76d8\u7684\u8bfb\u5199\u901f\u5ea6\u53ef\u80fd\u4f1a\u5f71\u54cdPython\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002\u6b64\u5916\uff0c\u67d0\u4e9b\u6a21\u5757\u6216\u5e93\u53ef\u80fd\u4f9d\u8d56\u4e8e\u7cfb\u7edf\u73af\u5883\uff0c\u56e0\u6b64\u5728\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u65f6\uff0c\u786e\u4fdd\u8fd9\u4e9b\u4f9d\u8d56\u9879\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\u4e5f\u662f\u5f88\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06Python\u9879\u76ee\u8fc1\u79fb\u5230U\u76d8\u4ee5\u4fbf\u4e8e\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u4f7f\u7528\uff1f<\/strong><br \/>\u8fc1\u79fbPython\u9879\u76ee\u5230U\u76d8\u7684\u6700\u4f73\u65b9\u6cd5\u662f\u5c06\u9879\u76ee\u6587\u4ef6\u5939\u5b8c\u6574\u590d\u5236\u5230U\u76d8\u4e2d\u3002\u786e\u4fdd\u5305\u542b\u6240\u6709\u5fc5\u8981\u7684\u6e90\u4ee3\u7801\u6587\u4ef6\u3001\u4f9d\u8d56\u7684\u5e93\u548c\u914d\u7f6e\u6587\u4ef6\u3002\u5982\u679c\u9879\u76ee\u4f7f\u7528\u4e86\u865a\u62df\u73af\u5883\uff0c\u5efa\u8bae\u5728U\u76d8\u4e0a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff0c\u5e76\u5728\u5176\u4e2d\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u9879\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u8fd0\u884c\u65f6\u4e0d\u4f1a\u51fa\u73b0\u7248\u672c\u4e0d\u517c\u5bb9\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5c06Python\u79fb\u5230U\u76d8\u4e2d\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4fbf\u643a\u7248Python\u3001\u5728U\u76d8\u4e2d\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u590d\u5236\u9879\u76ee\u6587\u4ef6\u5230U\u76d8\u3001\u5b89 [&hellip;]","protected":false},"author":3,"featured_media":1089204,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1089198"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1089198"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1089198\/revisions"}],"predecessor-version":[{"id":1089205,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1089198\/revisions\/1089205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1089204"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1089198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1089198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1089198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}