{"id":1084182,"date":"2025-01-08T13:04:58","date_gmt":"2025-01-08T05:04:58","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1084182.html"},"modified":"2025-01-08T13:05:01","modified_gmt":"2025-01-08T05:05:01","slug":"%e5%a6%82%e4%bd%95%e4%bb%8e%e5%91%bd%e4%bb%a4%e8%a1%8c%e8%bf%9b%e5%85%a5python-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1084182.html","title":{"rendered":"\u5982\u4f55\u4ece\u547d\u4ee4\u884c\u8fdb\u5165python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24194652\/ec6cd0a8-2148-414c-8c58-f71d03296d09.webp\" alt=\"\u5982\u4f55\u4ece\u547d\u4ee4\u884c\u8fdb\u5165python\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528\u547d\u4ee4\u884c\u8fdb\u5165Python\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3001\u8f93\u5165&quot;python&quot;\u547d\u4ee4\u3001\u68c0\u67e5\u5b89\u88c5\u8def\u5f84\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong>\u3002\u5176\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u70b9\u662f<strong>\u786e\u4fddPython\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u4e86\u73af\u5883\u53d8\u91cf<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26<\/p>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0b &quot;Win + R&quot; \u952e\uff0c\u8f93\u5165 &quot;cmd&quot; \u540e\u6309\u56de\u8f66\u952e\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5bf9\u4e8eMac\u548cLinux\u7528\u6237\uff0c\u53ef\u4ee5\u76f4\u63a5\u6253\u5f00\u7ec8\u7aef\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u8f93\u5165&quot;python&quot;\u547d\u4ee4<\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\uff0c\u8f93\u5165 &quot;python&quot; \u5e76\u6309\u4e0b\u56de\u8f66\u952e\u3002\u5982\u679cPython\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\uff0c\u4f60\u5c06\u770b\u5230Python\u7684\u7248\u672c\u4fe1\u606f\uff0c\u5e76\u8fdb\u5165\u5230Python\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u73af\u5883\u3002\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u5982\u4e0b\u7684\u63d0\u793a\u7b26\uff1a<\/p>\n<\/p>\n<p><pre><code>Python 3.9.6 (default, Jun 28 2021, 08:57:49)<\/p>\n<p>[GCC 8.4.0] on linux<\/p>\n<p>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<\/p>\n<p>&gt;&gt;&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u65f6\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u8fdb\u5165\u4e86Python\u73af\u5883\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u8fd9\u91cc\u8f93\u5165Python\u4ee3\u7801\u5e76\u6267\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u68c0\u67e5\u5b89\u88c5\u8def\u5f84<\/p>\n<\/p>\n<p><p>\u5982\u679c\u8f93\u5165 &quot;python&quot; \u547d\u4ee4\u540e\uff0c\u7cfb\u7edf\u63d0\u793a\u627e\u4e0d\u5230Python\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPython\u6ca1\u6709\u6b63\u786e\u5b89\u88c5\u6216\u662f\u73af\u5883\u53d8\u91cf\u6ca1\u6709\u914d\u7f6e\u597d\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u68c0\u67e5Python\u7684\u5b89\u88c5\u8def\u5f84\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165 &quot;where python&quot;\uff08Windows\u7cfb\u7edf\uff09\u6216 &quot;which python&quot;\uff08Mac\u548cLinux\u7cfb\u7edf\uff09\u3002<\/li>\n<li>\u5982\u679c\u7cfb\u7edf\u8fd4\u56dePython\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u8bf4\u660ePython\u5df2\u7ecf\u5b89\u88c5\uff0c\u53ea\u662f\u6ca1\u6709\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\u56fe\u6807\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e2d\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u53cc\u51fb\u5b83\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u8fdb\u53bb\u3002\u4f8b\u5982\uff0cC:\\Python39\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u8bbe\u7f6e\u3002<\/li>\n<\/ol>\n<p><p>\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 .bash_profile \u6216 .bashrc \u6587\u4ef6\u6765\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165 <code>nano ~\/.bash_profile<\/code> \u6216 <code>nano ~\/.bashrc<\/code>\u3002<\/li>\n<li>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u884c\uff1a<code>export PATH=&quot;\/usr\/local\/bin\/python3:$PATH&quot;<\/code>\u3002<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u3002<\/li>\n<li>\u8f93\u5165 <code>source ~\/.bash_profile<\/code> \u6216 <code>source ~\/.bashrc<\/code> \u4f7f\u914d\u7f6e\u751f\u6548\u3002<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5b89\u88c5\u5e76\u7ba1\u7406Python\u7248\u672c<\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u4f60\u53ef\u80fd\u9700\u8981\u5b89\u88c5\u4e0d\u540c\u7248\u672c\u7684Python\uff0c\u6216\u8005\u5728\u591a\u4e2a\u7248\u672c\u4e4b\u95f4\u5207\u6362\u3002\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982 &quot;pyenv&quot; \u6765\u5e2e\u52a9\u4f60\u7ba1\u7406\u4e0d\u540c\u7248\u672c\u7684Python\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5 pyenv\uff1a<\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8eMac\u548cLinux\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 pyenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bf9\u4e8eWindows\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528 pyenv-win\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">git clone https:\/\/github.com\/pyenv-win\/pyenv-win.git %USERPROFILE%\\.pyenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">export PATH=&quot;$HOME\/.pyenv\/bin:$PATH&quot;<\/p>\n<p>eval &quot;$(pyenv init --path)&quot;<\/p>\n<p>eval &quot;$(pyenv init -)&quot;<\/p>\n<p>eval &quot;$(pyenv virtualenv-init -)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u5b89\u88c5Python\u7248\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">pyenv install 3.9.6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u8bbe\u7f6e\u5168\u5c40\u6216\u5c40\u90e8Python\u7248\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">pyenv global 3.9.6<\/p>\n<p>pyenv local 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u865a\u62df\u73af\u5883\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u907f\u514d\u5168\u5c40Python\u5e93\u7684\u7248\u672c\u51b2\u7a81\u548c\u7ba1\u7406\u6df7\u4e71\uff0c\u63a8\u8350\u4f7f\u7528Python\u7684\u865a\u62df\u73af\u5883\u3002\u53ef\u4ee5\u4f7f\u7528 <code>venv<\/code> \u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<p>\u5728Windows\u7cfb\u7edf\uff1a<\/li>\n<\/p>\n<\/ol>\n<p><pre><code class=\"language-sh\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Mac\u548cLinux\u7cfb\u7edf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u9700\u8981\u7684\u5e93\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python\u7248\u672c\u95ee\u9898<\/strong>\uff1a\u6709\u65f6\u5019\u7cfb\u7edf\u9ed8\u8ba4\u7684Python\u7248\u672c\u4e0d\u662f\u4f60\u9700\u8981\u7684\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>python3<\/code> \u547d\u4ee4\u6765\u4f7f\u7528Python 3.x\u7248\u672c\u3002\u5982\u679c\u8fd8\u662f\u4e0d\u884c\uff0c\u53ef\u4ee5\u68c0\u67e5Python\u7684\u5b89\u88c5\u76ee\u5f55\u5e76\u624b\u52a8\u6307\u5b9a\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u5728\u5b89\u88c5\u6216\u914d\u7f6e\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6743\u9650\u95ee\u9898\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u7ba1\u7406\u5458\u6743\u9650\u8fd0\u884c\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff0c\u6216\u8005\u4f7f\u7528 <code>sudo<\/code> \u547d\u4ee4\uff08\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u73af\u5883\u53d8\u91cf\u95ee\u9898<\/strong>\uff1a\u5982\u679c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u540e\u4ecd\u7136\u65e0\u6cd5\u627e\u5230Python\uff0c\u53ef\u4ee5\u91cd\u542f\u8ba1\u7b97\u673a\u6216\u91cd\u65b0\u52a0\u8f7d\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u4ece\u547d\u4ee4\u884c\u8fdb\u5165Python\uff0c\u5e76\u719f\u7ec3\u5730\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884cPython\u4ee3\u7801\u3002\u786e\u4fddPython\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u662f\u6700\u5173\u952e\u7684\u4e00\u6b65\uff0c\u8fd9\u5c06\u5e2e\u52a9\u4f60\u987a\u5229\u5730\u8fdb\u5165Python\u73af\u5883\u5e76\u8fdb\u884c\u5f00\u53d1\u3002\u540c\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406Python\u5e93\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u5168\u5c40\u5e93\u7248\u672c\u51b2\u7a81\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u68c0\u67e5\u662f\u5426\u5df2\u5b89\u88c5Python\uff1f<\/strong><br \/>\u8981\u68c0\u67e5\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u53ef\u4ee5\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff08Windows\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u201ccmd\u201d\uff0cMac\u548cLinux\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u201cTerminal\u201d\uff09\u3002\u8f93\u5165 <code>python --version<\/code> \u6216 <code>python3 --version<\/code>\uff0c\u7136\u540e\u6309\u56de\u8f66\u3002\u5982\u679c\u5b89\u88c5\u6210\u529f\uff0c\u60a8\u5c06\u770b\u5230Python\u7684\u7248\u672c\u53f7\u3002\u82e5\u672a\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5728\u547d\u4ee4\u884c\u4e2d\u8fdb\u5165Python\u540e\uff0c\u5982\u4f55\u9000\u51fa\uff1f<\/strong><br \/>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165Python\u540e\uff0c\u60a8\u4f1a\u8fdb\u5165Python\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\u3002\u8981\u9000\u51fa\u8be5\u73af\u5883\uff0c\u53ef\u4ee5\u8f93\u5165 <code>exit()<\/code> \u6216\u4f7f\u7528\u5feb\u6377\u952e <code>Ctrl + Z<\/code>\uff08Windows\uff09\u6216 <code>Ctrl + D<\/code>\uff08Mac\/Linux\uff09\uff0c\u7136\u540e\u6309\u56de\u8f66\u3002\u8fd9\u6837\u60a8\u5c31\u4f1a\u8fd4\u56de\u5230\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<p><strong>\u5982\u679c\u547d\u4ee4\u884c\u4e2d\u51fa\u73b0\u201cpython\u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4\u201d\u8be5\u600e\u4e48\u529e\uff1f<\/strong><br \/>\u51fa\u73b0\u8fd9\u4e2a\u63d0\u793a\u901a\u5e38\u610f\u5473\u7740Python\u672a\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u91cd\u65b0\u5b89\u88c5Python\u5e76\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u6216\u8005\uff0c\u60a8\u4e5f\u53ef\u4ee5\u624b\u52a8\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u547d\u4ee4\u884c\u80fd\u591f\u8bc6\u522b\u5b83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528\u547d\u4ee4\u884c\u8fdb\u5165Python\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3001\u8f93\u5165&quot;python&quot;\u547d\u4ee4\u3001\u68c0\u67e5\u5b89\u88c5\u8def [&hellip;]","protected":false},"author":3,"featured_media":1084193,"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\/1084182"}],"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=1084182"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084182\/revisions"}],"predecessor-version":[{"id":1084195,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084182\/revisions\/1084195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1084193"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1084182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1084182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1084182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}