{"id":1018408,"date":"2024-12-27T12:42:10","date_gmt":"2024-12-27T04:42:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1018408.html"},"modified":"2024-12-27T12:42:12","modified_gmt":"2024-12-27T04:42:12","slug":"%e5%a6%82%e4%bd%95%e5%bb%ba%e7%ab%8bpython%e8%99%9a%e6%8b%9f%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1018408.html","title":{"rendered":"\u5982\u4f55\u5efa\u7acbpython\u865a\u62df\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25161113\/34e087af-3bdd-42a4-8e0a-ccb05c6816bc.webp\" alt=\"\u5982\u4f55\u5efa\u7acbpython\u865a\u62df\u5e93\" \/><\/p>\n<p><p> \u5efa\u7acbPython\u865a\u62df\u5e93\u7684\u5173\u952e\u6b65\u9aa4\u5305\u62ec<strong>\u9009\u62e9Python\u7248\u672c\u3001\u5b89\u88c5\u865a\u62df\u73af\u5883\u5de5\u5177\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/strong>\u3002\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5728\u4e0d\u540c\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u548c\u4f9d\u8d56\u5305\uff0c\u907f\u514d\u7248\u672c\u51b2\u7a81\uff0c\u4fdd\u6301\u9879\u76ee\u7684\u72ec\u7acb\u6027\u3002\u5c24\u5176\u662f\u5728\u56e2\u961f\u534f\u4f5c\u4e2d\uff0c\u865a\u62df\u73af\u5883\u53ef\u4ee5\u786e\u4fdd\u6240\u6709\u5f00\u53d1\u8005\u5728\u76f8\u540c\u7684\u73af\u5883\u4e2d\u5de5\u4f5c\uff0c\u51cf\u5c11\u201c\u5728\u6211\u7684\u673a\u5668\u4e0a\u53ef\u4ee5\u8fd0\u884c\u201d\u7684\u95ee\u9898\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u521b\u5efa\u5e76\u7ba1\u7406Python\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u9009\u62e9Python\u7248\u672c\u662f\u5efa\u7acb\u865a\u62df\u5e93\u7684\u7b2c\u4e00\u6b65\u3002\u786e\u4fdd\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4e86\u6b63\u786e\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pyenv<\/code>\u7b49\u5de5\u5177\u6765\u7ba1\u7406\u591a\u4e2a\u7248\u672c\u7684Python\u3002\u5728\u5b89\u88c5\u865a\u62df\u73af\u5883\u5de5\u5177\u65f6\uff0c<code>venv<\/code>\u548c<code>virtualenv<\/code>\u662f\u5e38\u7528\u7684\u9009\u62e9\u3002<code>venv<\/code>\u662fPython\u81ea\u5e26\u7684\u865a\u62df\u73af\u5883\u6a21\u5757\uff0c\u800c<code>virtualenv<\/code>\u5219\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\u548c\u517c\u5bb9\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u9009\u62e9Python\u7248\u672c<\/h3>\n<\/p>\n<p><p>\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u662f\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u7b2c\u4e00\u6b65\u3002\u4e0d\u540c\u7684\u9879\u76ee\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7684Python\u7248\u672c\uff0c\u5c24\u5176\u662f\u5f53\u9879\u76ee\u4f9d\u8d56\u7684\u67d0\u4e9b\u5e93\u4ec5\u652f\u6301\u7279\u5b9a\u7248\u672c\u65f6\u3002\u4f7f\u7528<code>pyenv<\/code>\u662f\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u7684\u4e00\u4e2a\u597d\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5Pyenv\uff1a<\/strong>Pyenv\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u7684\u5de5\u5177\u3002\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u7cfb\u7edf\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86<code>git<\/code>\u548c<code>curl<\/code>\uff0c\u7136\u540e\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pyenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u7740\uff0c\u9700\u8981\u5728shell\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0c\u4ee5\u4fbf\u80fd\u591f\u4f7f\u7528Pyenv\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;$HOME\/.pyenv\/bin:$PATH&quot;<\/p>\n<p>eval &quot;$(pyenv init --path)&quot;<\/p>\n<p>eval &quot;$(pyenv virtualenv-init -)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python\u7248\u672c\uff1a<\/strong>\u4f7f\u7528Pyenv\u53ef\u4ee5\u5b89\u88c5\u6307\u5b9a\u7684Python\u7248\u672c\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5Python 3.8\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.8.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pyenv global<\/code>\u6216<code>pyenv local<\/code>\u547d\u4ee4\u6765\u8bbe\u7f6e\u5168\u5c40\u6216\u5f53\u524d\u76ee\u5f55\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u5b89\u88c5\u865a\u62df\u73af\u5883\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u597dPython\u7248\u672c\u540e\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u5b89\u88c5\u865a\u62df\u73af\u5883\u5de5\u5177\u3002<code>venv<\/code>\u548c<code>virtualenv<\/code>\u662f\u4e24\u79cd\u5e38\u7528\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u4f7f\u7528venv\uff1a<\/strong>Python\u81ea\u5e26\u7684<code>venv<\/code>\u6a21\u5757\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u8981\u4f7f\u7528<code>venv<\/code>\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Python 3.3\u4ee5\u4e0a\u7684\u7248\u672c\uff0c\u56e0\u4e3a<code>venv<\/code>\u662f\u4ece\u8fd9\u4e2a\u7248\u672c\u5f00\u59cb\u5f15\u5165\u7684\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528virtualenv\uff1a<\/strong><code>virtualenv<\/code>\u662f\u4e00\u4e2a\u7b2c\u4e09\u65b9\u5de5\u5177\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u529f\u80fd\u3002\u5b83\u53ef\u4ee5\u5b89\u88c5\u5728Python 2\u548cPython 3\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install virtualenv<\/p>\n<p>virtualenv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>virtualenv<\/code>\u76f8\u6bd4<code>venv<\/code>\uff0c\u5176\u4f18\u52bf\u5728\u4e8e\u517c\u5bb9\u6027\u66f4\u597d\uff0c\u5c24\u5176\u662f\u5728Python 2.x\u73af\u5883\u4e0b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u865a\u62df\u73af\u5883\u662f\u4e3a\u9879\u76ee\u5206\u914d\u4e00\u4e2a\u72ec\u7acb\u7684Python\u8fd0\u884c\u73af\u5883\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u521b\u5efa\u73af\u5883\uff1a<\/strong>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\uff0c\u4f7f\u7528<code>venv<\/code>\u6216<code>virtualenv<\/code>\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u4f7f\u7528<code>virtualenv<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">virtualenv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542bPython\u53ef\u6267\u884c\u6587\u4ef6\u548c\u4e00\u7cfb\u5217\u811a\u672c\uff0c\u7528\u4e8e\u7ba1\u7406\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u76ee\u5f55\u7ed3\u6784\uff1a<\/strong>\u521b\u5efa\u865a\u62df\u73af\u5883\u540e\uff0c\u76ee\u5f55\u7ed3\u6784\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>bin\/<\/code>\uff1a\u5305\u542b\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/li>\n<li><code>lib\/<\/code>\uff1a\u5305\u542bPython\u5e93\u3002<\/li>\n<li><code>include\/<\/code>\uff1a\u5305\u542bC\u5934\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u662f\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u5173\u952e\u6b65\u9aa4\uff0c\u5b83\u786e\u4fdd\u6240\u6709\u7684Python\u547d\u4ee4\u548c\u5305\u7ba1\u7406\u64cd\u4f5c\u90fd\u662f\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fdb\u884c\u7684\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u6fc0\u6d3b\u73af\u5883\uff1a<\/strong>\u5728\u521b\u5efa\u865a\u62df\u73af\u5883\u540e\uff0c\u9700\u8981\u6fc0\u6d3b\u5b83\u3002\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u65b9\u6cd5\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e0d\u540c\u800c\u6709\u6240\u533a\u522b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Unix\u6216MacOS\u4e0a\uff1a\n<pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5728Windows\u4e0a\uff1a\n<pre><code class=\"language-bash\">.\\myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u6548\u679c\uff1a<\/strong>\u6fc0\u6d3b\u540e\uff0c\u547d\u4ee4\u63d0\u793a\u7b26\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u8be5\u73af\u5883\u3002\u4f8b\u5982\uff0c\u6fc0\u6d3b<code>myenv<\/code>\u540e\uff0c\u63d0\u793a\u7b26\u53ef\u80fd\u4f1a\u663e\u793a\u4e3a<code>(myenv) user@machine:~$<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/h3>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56\u662f\u786e\u4fdd\u9879\u76ee\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u7684\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\uff1a<\/strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5<code>requests<\/code>\u5e93\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u4f9d\u8d56\uff1a<\/strong>\u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u901a\u5e38\u4f1a\u5c06\u6240\u6709\u4f9d\u8d56\u5217\u5728\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u8be5\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u5728\u53e6\u4e00\u4e2a\u73af\u5883\u4e2d\u5b89\u88c5\u76f8\u540c\u7684\u4f9d\u8d56\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u9000\u51fa\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u9000\u51fa\u865a\u62df\u73af\u5883\u662f\u4e00\u4e2a\u826f\u597d\u7684\u4e60\u60ef\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u9000\u51fa\u73af\u5883\uff1a<\/strong>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a\n<pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p>\u9000\u51fa\u540e\uff0c\u547d\u4ee4\u63d0\u793a\u7b26\u5c06\u6062\u590d\u5230\u6fc0\u6d3b\u524d\u7684\u72b6\u6001\uff0c\u8868\u793a\u5f53\u524d\u4e0d\u518d\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/p>\n<\/ul>\n<p><h3>\u4e03\u3001\u66f4\u65b0\u548c\u5220\u9664\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u7ba1\u7406\u865a\u62df\u73af\u5883\u4e0d\u4ec5\u5305\u62ec\u521b\u5efa\u548c\u6fc0\u6d3b\uff0c\u8fd8\u5305\u62ec\u66f4\u65b0\u548c\u5220\u9664\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u66f4\u65b0\u73af\u5883\uff1a<\/strong>\u6709\u65f6\u9700\u8981\u66f4\u65b0\u865a\u62df\u73af\u5883\u4e2d\u7684\u67d0\u4e9b\u5305\u3002\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u66f4\u65b0\u67d0\u4e2a\u7279\u5b9a\u7684\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5220\u9664\u73af\u5883\uff1a<\/strong>\u5982\u679c\u4e0d\u518d\u9700\u8981\u67d0\u4e2a\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u5176\u76ee\u5f55\u6765\u79fb\u9664\u5b83\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">rm -rf myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5220\u9664\u76ee\u5f55\u540e\uff0c\u76f8\u5173\u7684\u6240\u6709\u6587\u4ef6\u90fd\u4f1a\u88ab\u79fb\u9664\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u516b\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7ba1\u7406\u548c\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u5f00\u53d1\u8005\u5e94\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u4fdd\u6301\u73af\u5883\u6574\u6d01\uff1a<\/strong>\u5b9a\u671f\u68c0\u67e5\u5e76\u6e05\u7406\u4e0d\u518d\u9700\u8981\u7684\u865a\u62df\u73af\u5883\u548c\u5305\uff0c\u907f\u514d\u5360\u7528\u8fc7\u591a\u7684\u78c1\u76d8\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7248\u672c\u63a7\u5236\uff1a<\/strong>\u5c06<code>requirements.txt<\/code>\u6587\u4ef6\u52a0\u5165\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u4e2d\uff0c\u4ee5\u4fbf\u56e2\u961f\u6210\u5458\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u6240\u9700\u7684\u4f9d\u8d56\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6587\u6863\u5316\uff1a<\/strong>\u5728\u9879\u76ee\u6587\u6863\u4e2d\u8bb0\u5f55\u5982\u4f55\u521b\u5efa\u548c\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u4ee5\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u80fd\u591f\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u73af\u5883\u9694\u79bb\uff1a<\/strong>\u5bf9\u4e8e\u4e0d\u540c\u7684\u9879\u76ee\uff0c\u59cb\u7ec8\u521b\u5efa\u72ec\u7acb\u7684\u865a\u62df\u73af\u5883\uff0c\u786e\u4fdd\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u548c\u5b9e\u8df5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u521b\u5efa\u548c\u7ba1\u7406Python\u865a\u62df\u73af\u5883\uff0c\u4ece\u800c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u521b\u5efaPython\u865a\u62df\u73af\u5883\uff1f<\/strong><br \/>\u5728Windows\u3001macOS\u548cLinux\u7b49\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u521b\u5efaPython\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\u6709\u6240\u4e0d\u540c\u3002\u5728Windows\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u63d0\u793a\u7b26\u6216PowerShell\uff0c\u8f93\u5165<code>python -m venv myenv<\/code>\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u5728macOS\u548cLinux\u4e2d\uff0c\u4f7f\u7528\u7ec8\u7aef\uff0c\u53ef\u4ee5\u6267\u884c\u540c\u6837\u7684\u547d\u4ee4\u3002\u786e\u4fdd\u5728\u521b\u5efa\u865a\u62df\u73af\u5883\u524d\u5df2\u5b89\u88c5Python\u5e76\u6dfb\u52a0\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u6211\u9700\u8981\u4f7f\u7528Python\u865a\u62df\u73af\u5883\uff1f<\/strong><br \/>Python\u865a\u62df\u73af\u5883\u5141\u8bb8\u7528\u6237\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u521b\u5efa\u591a\u4e2a\u72ec\u7acb\u7684\u73af\u5883\uff0c\u6bcf\u4e2a\u73af\u5883\u90fd\u6709\u81ea\u5df1\u7684\u4f9d\u8d56\u5305\u548cPython\u7248\u672c\u3002\u8fd9\u6709\u52a9\u4e8e\u907f\u514d\u7248\u672c\u51b2\u7a81\u548c\u4f9d\u8d56\u95ee\u9898\uff0c\u786e\u4fdd\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270\uff0c\u7279\u522b\u662f\u5728\u5f00\u53d1\u5927\u578b\u5e94\u7528\u6216\u4f7f\u7528\u4e0d\u540c\u5e93\u7248\u672c\u65f6\u3002<\/p>\n<p><strong>\u5982\u4f55\u6fc0\u6d3b\u548c\u9000\u51faPython\u865a\u62df\u73af\u5883\uff1f<\/strong><br \/>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\u56e0\u64cd\u4f5c\u7cfb\u7edf\u800c\u5f02\u3002\u5728Windows\u4e0a\uff0c\u4f7f\u7528<code>myenv\\Scripts\\activate<\/code>\uff0c\u5728macOS\u548cLinux\u4e0a\uff0c\u6267\u884c<code>source myenv\/bin\/activate<\/code>\u3002\u6fc0\u6d3b\u540e\uff0c\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002\u8981\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u7b80\u5355\u8f93\u5165<code>deactivate<\/code>\u547d\u4ee4\uff0c\u8fd9\u6837\u4f1a\u8fd4\u56de\u5230\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5efa\u7acbPython\u865a\u62df\u5e93\u7684\u5173\u952e\u6b65\u9aa4\u5305\u62ec\u9009\u62e9Python\u7248\u672c\u3001\u5b89\u88c5\u865a\u62df\u73af\u5883\u5de5\u5177\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u9879 [&hellip;]","protected":false},"author":3,"featured_media":1018417,"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\/1018408"}],"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=1018408"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018408\/revisions"}],"predecessor-version":[{"id":1018419,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018408\/revisions\/1018419"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1018417"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1018408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1018408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1018408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}