{"id":921817,"date":"2024-12-26T14:20:20","date_gmt":"2024-12-26T06:20:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/921817.html"},"modified":"2024-12-26T14:20:22","modified_gmt":"2024-12-26T06:20:22","slug":"%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aepython%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/921817.html","title":{"rendered":"\u5982\u4f55\u914d\u7f6epython\u73af\u5883"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210528\/ce1b72da-4bf8-450f-ac03-4f53eda5a080.webp\" alt=\"\u5982\u4f55\u914d\u7f6epython\u73af\u5883\" \/><\/p>\n<p><p> \u4e00\u3001\u5728Windows\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883<\/p>\n<\/p>\n<p><p><strong>\u5728Windows\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u4e0b\u8f7d\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5Python\u5305\u7ba1\u7406\u5de5\u5177pip\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/strong>\u5176\u4e2d\uff0c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u662f\u5173\u952e\u6b65\u9aa4\uff0c\u5b83\u786e\u4fddPython\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u88ab\u6b63\u786e\u8bc6\u522b\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Windows\u7cfb\u7edf\u4e2d\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4e0b\u8f7d\u5b89\u88c5Python<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u9002\u5408Windows\u7684Python\u5b89\u88c5\u5305\u3002\u4e00\u822c\u5efa\u8bae\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u8fd0\u884c\u5b89\u88c5\u5305\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u52a1\u5fc5\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u6837\u53ef\u4ee5\u81ea\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u5728\u5b89\u88c5\u65f6\u6ca1\u6709\u52fe\u9009\u201cAdd Python to PATH\u201d\uff0c\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e0b\uff0c\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u70b9\u51fb\u201c\u7f16\u8f91\u201d\uff0c\u7136\u540e\u6dfb\u52a0Python\u7684\u5b89\u88c5\u8def\u5f84\u548cScripts\u6587\u4ef6\u5939\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u82e5Python\u5b89\u88c5\u5728C:\\Python39\uff0c\u5219\u9700\u8981\u6dfb\u52a0C:\\Python39\u548cC:\\Python39\\Scripts\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5728MacOS\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883<\/p>\n<\/p>\n<p><p><strong>\u5728MacOS\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u4f7f\u7528Homebrew\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5pip\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/strong>Homebrew\u662fMacOS\u4e0a\u5e38\u7528\u7684\u8f6f\u4ef6\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u548c\u7ba1\u7406\u8f6f\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528Homebrew\u5b89\u88c5Python<\/strong><\/li>\n<\/ol>\n<p><p>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Homebrew\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/bin\/bash -c &quot;$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>python3 --version<\/code>\u6765\u68c0\u67e5Python\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/li>\n<\/ol>\n<p><p>\u901a\u5e38\u4f7f\u7528Homebrew\u5b89\u88c5Python\u540e\uff0c\u4e0d\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f46\u5982\u679c\u9700\u8981\u624b\u52a8\u914d\u7f6e\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u6253\u5f00<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/usr\/local\/opt\/python\/libexec\/bin:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u4f7f\u7528<code>source ~\/.bash_profile<\/code>\u6216<code>source ~\/.zshrc<\/code>\u547d\u4ee4\u4f7f\u914d\u7f6e\u751f\u6548\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883<\/p>\n<\/p>\n<p><p><strong>\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5pip\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/strong>\u4e0d\u540cLinux\u53d1\u884c\u7248\u4f7f\u7528\u7684\u5305\u7ba1\u7406\u5668\u53ef\u80fd\u4e0d\u540c\uff0c\u4f8b\u5982Ubuntu\u4f7f\u7528apt\uff0cCentOS\u4f7f\u7528yum\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5Python<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Ubuntu\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p>sudo apt install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728CentOS\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo yum install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>python3 --version<\/code>\u6765\u68c0\u67e5Python\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5b89\u88c5\u5b8c\u6210\u540e\u4e0d\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f46\u5982\u679c\u9700\u8981\uff0c\u53ef\u4ee5\u7f16\u8f91<code>~\/.bashrc<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0Python\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/usr\/bin\/python3:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u540e\uff0c\u4f7f\u7528<code>source ~\/.bashrc<\/code>\u547d\u4ee4\u4f7f\u914d\u7f6e\u751f\u6548\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5b89\u88c5Python\u5305\u7ba1\u7406\u5de5\u5177pip<\/p>\n<\/p>\n<p><p><strong>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/strong>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0cPython\u5b89\u88c5\u5305\u4e2d\u5df2\u7ecf\u5305\u542b\u4e86pip\uff0c\u4f46\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u624b\u52a8\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5728Windows\u7cfb\u7edf\u4e2d\u5b89\u88c5pip<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u5728\u5b89\u88c5Python\u65f6\u6ca1\u6709\u9009\u62e9\u5b89\u88c5pip\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u5b89\u88c5\u3002\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m ensurepip --default-pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5728MacOS\u548cLinux\u7cfb\u7edf\u4e2d\u5b89\u88c5pip<\/strong><\/li>\n<\/ol>\n<p><p>\u5728MacOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u901a\u5e38pip\u4f1a\u4e0ePython\u4e00\u8d77\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt install python3-pip  # Ubuntu<\/p>\n<p>sudo yum install python3-pip  # CentOS<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u521b\u5efaPython\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p><strong>Python\u865a\u62df\u73af\u5883\u7528\u4e8e\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u9632\u6b62\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5305\u7248\u672c\u51b2\u7a81\u3002<\/strong>\u53ef\u4ee5\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\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>\u8fd9\u91cc<code>myenv<\/code>\u662f\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66ff\u6362\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Windows\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728MacOS\u548cLinux\u4e2d\uff0c\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><p>\u6fc0\u6d3b\u540e\uff0c\u547d\u4ee4\u884c\u524d\u9762\u4f1a\u51fa\u73b0\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u5f53\u524d\u5904\u4e8e\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u3002\u4f8b\u5982\uff0c\u5b89\u88c5Flask\u6846\u67b6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fd0\u884c\u9879\u76ee\u4ee3\u7801\uff0c\u786e\u4fdd\u6240\u9700\u7684\u4f9d\u8d56\u90fd\u5df2\u6b63\u786e\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5b8c\u6210\u9879\u76ee\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9000\u51fa\u540e\uff0c\u547d\u4ee4\u884c\u524d\u9762\u7684\u865a\u62df\u73af\u5883\u540d\u79f0\u4f1a\u6d88\u5931\uff0c\u8868\u793a\u5df2\u8fd4\u56de\u5168\u5c40\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f7f\u7528Anaconda\u914d\u7f6ePython\u73af\u5883<\/p>\n<\/p>\n<p><p><strong>Anaconda\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u6570\u636e\u79d1\u5b66\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u5305\u7ba1\u7406\u548c\u73af\u5883\u7ba1\u7406\u529f\u80fd\u3002<\/strong>\u4f7f\u7528Anaconda\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u548c\u7ba1\u7406\u591a\u4e2aPython\u73af\u5883\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4e0b\u8f7d\u5b89\u88c5Anaconda<\/strong><\/li>\n<\/ol>\n<p><p>\u8bbf\u95eeAnaconda\u7684\u5b98\u65b9\u7f51\u7ad9\uff08anaconda.com\uff09\u4e0b\u8f7d\u9002\u5408\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u5b89\u88c5\u5305\u5e76\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u521b\u5efaAnaconda\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u6253\u5f00Anaconda Prompt\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08MacOS\/Linux\uff09\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u65b0\u7684Anaconda\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda create --name myenv python=3.9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc<code>myenv<\/code>\u662f\u73af\u5883\u7684\u540d\u79f0\uff0c<code>python=3.9<\/code>\u6307\u5b9aPython\u7248\u672c\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6fc0\u6d3bAnaconda\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3bAnaconda\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u53ef\u4ee5\u5728\u73af\u5883\u4e2d\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5b89\u88c5\u5305\u548c\u7ba1\u7406\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Anaconda\u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>conda install<\/code>\u547d\u4ee4\u5b89\u88c5\u5305\u3002\u4f8b\u5982\uff0c\u5b89\u88c5NumPy\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>conda list<\/code>\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u7684\u5305\u3002<\/p>\n<\/p>\n<ol start=\"5\">\n<li><strong>\u9000\u51faAnaconda\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9000\u51faAnaconda\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u914d\u7f6ePython\u73af\u5883\u662fPython\u5f00\u53d1\u7684\u57fa\u7840\u6b65\u9aa4\uff0c\u786e\u4fdd\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u987a\u5229\u8fd0\u884cPython\u7a0b\u5e8f\u3002<strong>\u5173\u952e\u6b65\u9aa4\u5305\u62ec\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5pip\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u6216\u4f7f\u7528Anaconda\u7ba1\u7406\u73af\u5883\u3002<\/strong>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u4f7f\u7528\u6240\u9700\u7684Python\u7248\u672c\u548c\u5305\uff0c\u907f\u514d\u4f9d\u8d56\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\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u8fdb\u884c\u73af\u5883\u914d\u7f6e\uff1f<\/strong><br \/>\u9009\u62e9Python\u7248\u672c\u65f6\uff0c\u5efa\u8bae\u6839\u636e\u9879\u76ee\u9700\u6c42\u548c\u517c\u5bb9\u6027\u6765\u51b3\u5b9a\u3002\u5bf9\u4e8e\u65b0\u9879\u76ee\uff0c\u4f7f\u7528\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\u901a\u5e38\u662f\u6700\u597d\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e86\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u66f4\u65b0\u3002\u5982\u679c\u60a8\u7684\u9879\u76ee\u4f9d\u8d56\u4e8e\u7279\u5b9a\u7684\u5e93\u6216\u6846\u67b6\uff0c\u786e\u4fdd\u8fd9\u4e9b\u4f9d\u8d56\u9879\u4e0e\u6240\u9009Python\u7248\u672c\u517c\u5bb9\u3002\u67e5\u770b\u5b98\u65b9\u6587\u6863\u548c\u5e93\u7684\u652f\u6301\u77e9\u9635\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u505a\u51fa\u660e\u667a\u7684\u51b3\u7b56\u3002<\/p>\n<p><strong>\u5728Windows\u548cMac\u4e0a\u914d\u7f6ePython\u73af\u5883\u6709\u4ec0\u4e48\u4e0d\u540c\u4e4b\u5904\uff1f<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7dPython\u5b89\u88c5\u7a0b\u5e8f\u5e76\u8fd0\u884c\u5b83\u6765\u914d\u7f6e\u73af\u5883\uff0c\u5b89\u88c5\u65f6\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\u3002\u5bf9\u4e8eMac\u7528\u6237\uff0c\u4f7f\u7528Homebrew\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u9009\u62e9\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u7b80\u5355\u5730\u5b89\u88c5\u548c\u7ba1\u7406Python\u7248\u672c\u3002\u4e24\u8005\u5728\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u4e0a\u6709\u6240\u4e0d\u540c\uff0cWindows\u901a\u5e38\u9700\u8981\u624b\u52a8\u6dfb\u52a0\uff0c\u800cMac\u5219\u901a\u5e38\u81ea\u52a8\u5904\u7406\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u7ba1\u7406Python\u9879\u76ee\u4f9d\u8d56\uff1f<\/strong><br \/>\u521b\u5efa\u865a\u62df\u73af\u5883\u80fd\u591f\u6709\u6548\u5730\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u3002\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528<code>python -m venv myenv<\/code>\u547d\u4ee4\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmyenv\u201d\u7684\u865a\u62df\u73af\u5883\u3002\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u6240\u6709\u5b89\u88c5\u7684\u5305\u90fd\u5c06\u4ec5\u9650\u4e8e\u8be5\u73af\u5883\uff0c\u4ece\u800c\u907f\u514d\u4e0e\u7cfb\u7edf\u7ea7Python\u5e93\u53d1\u751f\u51b2\u7a81\u3002\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u4f9d\u8d56\u65f6\uff0c\u5efa\u8bae\u521b\u5efa\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u65b9\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u5feb\u901f\u5b89\u88c5\u76f8\u540c\u7684\u4f9d\u8d56\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3Python\u73af\u5883\u914d\u7f6e\u4e2d\u5e38\u89c1\u7684\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u914d\u7f6ePython\u73af\u5883\u65f6\uff0c\u5e38\u89c1\u7684\u95ee\u9898\u5305\u62ec\u8def\u5f84\u8bbe\u7f6e\u9519\u8bef\u3001\u5305\u7248\u672c\u4e0d\u517c\u5bb9\u548c\u4f9d\u8d56\u7f3a\u5931\u7b49\u3002\u9047\u5230\u8def\u5f84\u95ee\u9898\u65f6\uff0c\u68c0\u67e5\u73af\u5883\u53d8\u91cf\u662f\u5426\u6b63\u786e\u8bbe\u7f6e\u975e\u5e38\u91cd\u8981\u3002\u5bf9\u4e8e\u5305\u7248\u672c\u4e0d\u517c\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5305\u7248\u672c\uff0c\u5e76\u624b\u52a8\u8c03\u6574\u3002\u82e5\u4f9d\u8d56\u7f3a\u5931\uff0c\u8fd0\u884c<code>pip install -r requirements.txt<\/code>\u53ef\u4ee5\u4e00\u6b21\u6027\u5b89\u88c5\u6240\u9700\u7684\u6240\u6709\u5305\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001\u5728Windows\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883 \u5728Windows\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u4e0b\u8f7d [&hellip;]","protected":false},"author":3,"featured_media":921819,"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\/921817"}],"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=921817"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/921817\/revisions"}],"predecessor-version":[{"id":921820,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/921817\/revisions\/921820"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/921819"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=921817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=921817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=921817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}