{"id":967334,"date":"2024-12-27T04:56:08","date_gmt":"2024-12-26T20:56:08","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/967334.html"},"modified":"2024-12-27T04:56:10","modified_gmt":"2024-12-26T20:56:10","slug":"python%e5%a6%82%e4%bd%95%e8%b0%83%e8%af%95%e5%ae%89%e8%a3%85%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/967334.html","title":{"rendered":"python\u5982\u4f55\u8c03\u8bd5\u5b89\u88c5\u95ee\u9898"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24182650\/05c27c3f-0df4-45bc-8c91-d426616eaa53.webp\" alt=\"python\u5982\u4f55\u8c03\u8bd5\u5b89\u88c5\u95ee\u9898\" \/><\/p>\n<p><p> \u5728\u89e3\u51b3Python\u5b89\u88c5\u95ee\u9898\u65f6\uff0c\u901a\u5e38\u9700\u8981\u9075\u5faa\u51e0\u4e2a\u6b65\u9aa4\u6765\u786e\u4fdd\u5b89\u88c5\u987a\u5229\u8fdb\u884c\u3002<strong>\u68c0\u67e5Python\u7248\u672c\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u3001\u68c0\u67e5\u8def\u5f84\u914d\u7f6e\u3001\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5<\/strong>\u662f\u5173\u952e\u6b65\u9aa4\u3002\u7279\u522b\u662f\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6781\u5927\u5730\u51cf\u5c11\u7248\u672c\u51b2\u7a81\u548c\u4f9d\u8d56\u95ee\u9898\u3002\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u9694\u79bb\u7684Python\u73af\u5883\uff0c\u53ef\u4ee5\u4fdd\u8bc1\u5b89\u88c5\u7684\u5305\u548c\u6a21\u5757\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u5176\u4ed6\u90e8\u5206\uff0c\u4ece\u800c\u7b80\u5316\u8c03\u8bd5\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u68c0\u67e5Python\u7248\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u4efb\u4f55\u5b89\u88c5\u95ee\u9898\u4e4b\u524d\uff0c\u9996\u5148\u8981\u786e\u8ba4\u4f60\u4f7f\u7528\u7684Python\u7248\u672c\u662f\u6b63\u786e\u7684\uff0c\u5e76\u4e14\u4e0e\u6240\u9700\u7684\u8f6f\u4ef6\u6216\u5305\u517c\u5bb9\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u5f53\u524dPython\u7248\u672c<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u67e5\u770b\u5f53\u524d\u5b89\u88c5\u7684\u7248\u672c\u3002\u786e\u4fdd\u4f60\u4f7f\u7528\u7684\u662f\u9879\u76ee\u6240\u9700\u7684\u7248\u672c\u3002<\/li>\n<li><strong>\u5347\u7ea7\u6216\u964d\u7ea7Python\u7248\u672c<\/strong>\uff1a\u5982\u679c\u53d1\u73b0\u7248\u672c\u4e0d\u517c\u5bb9\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5408\u9002\u7684\u7248\u672c\u6216\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\uff08\u5982pyenv\uff09\u6765\u5207\u6362\u7248\u672c\u3002<\/li>\n<li><strong>\u591a\u7248\u672c\u5171\u5b58<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u540c\u65f6\u4f7f\u7528\u591a\u4e2a\u7248\u672c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u5de5\u5177\u5982pyenv\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8f7b\u677e\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u4f60\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u4ece\u800c\u907f\u514d\u5305\u4e4b\u95f4\u7684\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528<code>python -m venv myenv<\/code>\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u6240\u9700\u7684\u5e93\u548c\u7248\u672c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40Python\u73af\u5883\u3002<\/li>\n<li><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728Windows\u4e0a\u4f7f\u7528<code>myenv\\Scripts\\activate<\/code>\uff0c\u5728macOS\u548cLinux\u4e0a\u4f7f\u7528<code>source myenv\/bin\/activate<\/code>\u6765\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/li>\n<li><strong>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/strong>\uff1a\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f7f\u7528<code>pip install -r requirements.txt<\/code>\u6765\u5b89\u88c5\u9879\u76ee\u7684\u6240\u6709\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u5b89\u88c5Python\u5305\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u4f9d\u8d56\u95ee\u9898\uff0c\u8fd9\u901a\u5e38\u662f\u7531\u4e8e\u7f3a\u5c11\u5fc5\u8981\u7684\u7cfb\u7edf\u5e93\u6216\u5de5\u5177\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u4f9d\u8d56<\/strong>\uff1a\u9605\u8bfb\u9879\u76ee\u7684\u6587\u6863\u6216README\u6587\u4ef6\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u3002\u67d0\u4e9b\u5305\u9700\u8981\u7279\u5b9a\u7684\u7cfb\u7edf\u5e93\uff0c\u5982C\u7f16\u8bd1\u5668\u6216\u5176\u4ed6\u5f00\u53d1\u5de5\u5177\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5305\u7ba1\u7406\u5668<\/strong>\uff1a\u5728Linux\u4e0a\uff0c\u4f7f\u7528<code>apt<\/code>\u6216<code>yum<\/code>\u7b49\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5\u7f3a\u5931\u7684\u4f9d\u8d56\u3002\u5728macOS\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528<code>brew<\/code>\u3002<\/li>\n<li><strong>\u89e3\u51b3\u51b2\u7a81<\/strong>\uff1a\u5982\u679c\u9047\u5230\u4f9d\u8d56\u51b2\u7a81\uff0c\u5c1d\u8bd5\u5347\u7ea7\u6216\u964d\u7ea7\u76f8\u5173\u7684\u5e93\u7248\u672c\uff0c\u6216\u8005\u54a8\u8be2\u9879\u76ee\u7684\u652f\u6301\u6e20\u9053\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u68c0\u67e5\u8def\u5f84\u914d\u7f6e<\/h3>\n<\/p>\n<p><p>\u8def\u5f84\u914d\u7f6e\u95ee\u9898\u53ef\u80fd\u5bfc\u81f4Python\u65e0\u6cd5\u6b63\u786e\u627e\u5230\u6216\u52a0\u8f7d\u67d0\u4e9b\u6a21\u5757\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u786e\u4fdd<code>PYTHONPATH<\/code>\u548c<code>PATH<\/code>\u53d8\u91cf\u4e2d\u5305\u542bPython\u5b89\u88c5\u76ee\u5f55\u548cScripts\u76ee\u5f55\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u800c\u4e0d\u662f\u76f8\u5bf9\u8def\u5f84\u53ef\u4ee5\u907f\u514d\u8def\u5f84\u95ee\u9898\u3002<\/li>\n<li><strong>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/strong>\uff1a\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e0a\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4fee\u6539<code>~\/.bashrc<\/code>\u6216<code>~\/.zshrc<\/code>\u7b49\u914d\u7f6e\u6587\u4ef6\u4ee5\u786e\u4fdd\u8def\u5f84\u6b63\u786e\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u95ee\u9898\u4ecd\u7136\u5b58\u5728\uff0c\u91cd\u65b0\u5b89\u88c5Python\u548c\u76f8\u5173\u5305\u53ef\u80fd\u662f\u6700\u540e\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u5378\u8f7d\u65e7\u7248\u672c<\/strong>\uff1a\u786e\u4fdd\u5f7b\u5e95\u5378\u8f7d\u5f53\u524d\u7684Python\u7248\u672c\u548c\u6240\u6709\u76f8\u5173\u5305\uff0c\u907f\u514d\u6b8b\u7559\u6587\u4ef6\u5bfc\u81f4\u95ee\u9898\u3002<\/li>\n<li><strong>\u6e05\u7406\u7f13\u5b58<\/strong>\uff1a\u4f7f\u7528<code>pip cache purge<\/code>\u6e05\u7406pip\u7f13\u5b58\uff0c\u907f\u514d\u7f13\u5b58\u6587\u4ef6\u5bfc\u81f4\u5b89\u88c5\u95ee\u9898\u3002<\/li>\n<li><strong>\u91cd\u65b0\u5b89\u88c5<\/strong>\uff1a\u4ecePython\u5b98\u7f51\u6216\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u91cd\u65b0\u5b89\u88c5Python\uff0c\u5e76\u9010\u6b65\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\uff0c\u786e\u4fdd\u6bcf\u4e00\u6b65\u90fd\u6210\u529f\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u9075\u5faa\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3Python\u5b89\u88c5\u95ee\u9898\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u786e\u4fdd\u5728\u6bcf\u4e00\u6b65\u4e2d\u4ed4\u7ec6\u68c0\u67e5\u8f93\u51fa\u4fe1\u606f\uff0c\u4ee5\u4fbf\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u6f5c\u5728\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u7684Python\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1f<\/strong><br \/>\u8981\u786e\u8ba4Python\u662f\u5426\u6210\u529f\u5b89\u88c5\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u5982\u679c\u8fd4\u56de\u4e86Python\u7684\u7248\u672c\u53f7\uff0c\u8868\u793a\u5b89\u88c5\u6210\u529f\u3002\u53e6\u5916\uff0c\u53ef\u4ee5\u8fd0\u884c\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\uff0c\u6bd4\u5982<code>print(&quot;Hello, World!&quot;)<\/code>\uff0c\u770b\u662f\u5426\u80fd\u591f\u6b63\u5e38\u8f93\u51fa\u3002<\/p>\n<p><strong>\u5728\u5b89\u88c5Python\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u5e94\u8be5\u600e\u4e48\u89e3\u51b3\uff1f<\/strong><br \/>\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\u3002\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u53f3\u952e\u70b9\u51fb\u5b89\u88c5\u6587\u4ef6\uff0c\u9009\u62e9\u201c\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u201d\u3002\u5728Linux\u6216macOS\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u524d\u52a0\u4e0a<code>sudo<\/code>\u6765\u63d0\u5347\u6743\u9650\uff0c\u4f8b\u5982<code>sudo apt-get install python3<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3Python\u5e93\u5b89\u88c5\u5931\u8d25\u7684\u95ee\u9898\uff1f<\/strong><br \/>\u5982\u679c\u5728\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u5e93\u65f6\u51fa\u73b0\u9519\u8bef\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u9996\u5148\uff0c\u786e\u4fdd<code>pip<\/code>\u5df2\u7ecf\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pip install --upgrade pip<\/code>\u547d\u4ee4\u5b9e\u73b0\u3002\u5176\u6b21\uff0c\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u6b63\u5e38\uff0c\u56e0\u4e3a\u7f51\u7edc\u95ee\u9898\u53ef\u80fd\u5bfc\u81f4\u5b89\u88c5\u5931\u8d25\u3002\u6b64\u5916\uff0c\u67d0\u4e9b\u5e93\u53ef\u80fd\u9700\u8981\u7279\u5b9a\u7684\u64cd\u4f5c\u7cfb\u7edf\u4f9d\u8d56\uff0c\u786e\u4fdd\u8fd9\u4e9b\u4f9d\u8d56\u5df2\u88ab\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770bPython\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u67e5\u770b\u73af\u5883\u53d8\u91cf\uff0c\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u88ab\u6dfb\u52a0\u5230\u4e86\u201cPath\u201d\u53d8\u91cf\u4e2d\u3002\u5728Linux\u6216macOS\u4e2d\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u8f93\u5165<code>echo $PATH<\/code>\u67e5\u770b\u5f53\u524d\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u3002\u5982\u679cPython\u8def\u5f84\u672a\u5305\u542b\u5728\u5185\uff0c\u53ef\u4ee5\u7f16\u8f91<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0\u76f8\u5e94\u7684\u8def\u5f84\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u89e3\u51b3Python\u5b89\u88c5\u95ee\u9898\u65f6\uff0c\u901a\u5e38\u9700\u8981\u9075\u5faa\u51e0\u4e2a\u6b65\u9aa4\u6765\u786e\u4fdd\u5b89\u88c5\u987a\u5229\u8fdb\u884c\u3002\u68c0\u67e5Python\u7248\u672c\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5 [&hellip;]","protected":false},"author":3,"featured_media":967341,"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\/967334"}],"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=967334"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/967334\/revisions"}],"predecessor-version":[{"id":967343,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/967334\/revisions\/967343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/967341"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=967334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=967334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=967334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}