{"id":968456,"date":"2024-12-27T05:07:18","date_gmt":"2024-12-26T21:07:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/968456.html"},"modified":"2024-12-27T05:07:21","modified_gmt":"2024-12-26T21:07:21","slug":"idea%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8cpython%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/968456.html","title":{"rendered":"idea\u5982\u4f55\u8fd0\u884cpython\u9879\u76ee"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183152\/697fcc6e-e463-429d-a61a-3103f2c21d0a.webp\" alt=\"idea\u5982\u4f55\u8fd0\u884cpython\u9879\u76ee\" \/><\/p>\n<p><p> <strong>\u8981\u8fd0\u884cPython\u9879\u76ee\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u4f9d\u8d56\u5e93\u3001\u914d\u7f6e\u9879\u76ee\u7ed3\u6784\u548c\u542f\u52a8\u9879\u76ee\u3002<\/strong> \u5728\u8fd9\u4e9b\u6b65\u9aa4\u4e2d\uff0c<strong>\u8bbe\u7f6e\u865a\u62df\u73af\u5883<\/strong>\u662f\u4e00\u4e2a\u5173\u952e\u73af\u8282\u3002\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u7248\u672c\u51b2\u7a81\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u5b89\u88c5Python\u89e3\u91ca\u5668<\/h2>\n<\/p>\n<p><p>\u5b89\u88c5Python\u89e3\u91ca\u5668\u662f\u8fd0\u884cPython\u9879\u76ee\u7684\u7b2c\u4e00\u6b65\u3002Python\u662f\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u9879\u76ee\u548c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u548c\u5b89\u88c5Python<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u524d\u5f80Python\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\uff0c\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u5b89\u88c5\u5305\u3002<\/li>\n<li>\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u52a1\u5fc5\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u67e5\u770b\u662f\u5426\u6210\u529f\u5b89\u88c5Python\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h2>\u4e8c\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883<\/h2>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u662fPython\u9879\u76ee\u5f00\u53d1\u4e2d\u7684\u91cd\u8981\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u786e\u4fdd\u9879\u76ee\u72ec\u7acb\u8fd0\u884c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u547d\u4ee4<code>python -m venv env<\/code>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cenv\u201d\u7684\u865a\u62df\u73af\u5883\u3002\u201cenv\u201d\u662f\u865a\u62df\u73af\u5883\u7684\u76ee\u5f55\u540d\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u884c\u547d\u540d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u4e0a\uff0c\u8fd0\u884c<code>.\\env\\Scripts\\activate<\/code>\u3002<\/li>\n<li>\u5728macOS\u548cLinux\u4e0a\uff0c\u8fd0\u884c<code>source env\/bin\/activate<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u865a\u62df\u73af\u5883\u6fc0\u6d3b<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u6fc0\u6d3b\u540e\uff0c\u60a8\u5e94\u8be5\u80fd\u5728\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u770b\u5230\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u5982\u201c(env)\u201d\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h2>\u4e09\u3001\u5b89\u88c5\u4f9d\u8d56\u5e93<\/h2>\n<\/p>\n<p><p>\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\u901a\u5e38\u8bb0\u5f55\u5728\u4e00\u4e2a\u540d\u4e3a<code>requirements.txt<\/code>\u7684\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa<code>requirements.txt<\/code>\u6587\u4ef6<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u9879\u76ee\u6ca1\u6709\u8be5\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>pip freeze &gt; requirements.txt<\/code>\u547d\u4ee4\u751f\u6210\u5f53\u524d\u73af\u5883\u4e0b\u7684\u4f9d\u8d56\u5217\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\u5e93<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u547d\u4ee4<code>pip install -r requirements.txt<\/code>\u5b89\u88c5\u6587\u4ef6\u4e2d\u5217\u51fa\u7684\u6240\u6709\u4f9d\u8d56\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h2>\u56db\u3001\u914d\u7f6e\u9879\u76ee\u7ed3\u6784<\/h2>\n<\/p>\n<p><p>\u826f\u597d\u7684\u9879\u76ee\u7ed3\u6784\u6709\u52a9\u4e8e\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u76ee\u5f55\u7ed3\u6784<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u901a\u5e38\u4e00\u4e2aPython\u9879\u76ee\u5305\u62ec\u4ee5\u4e0b\u76ee\u5f55\uff1a\n<pre><code>project_name\/<\/p>\n<p>\u251c\u2500\u2500 env\/<\/p>\n<p>\u251c\u2500\u2500 src\/<\/p>\n<p>\u2502   \u251c\u2500\u2500 __init__.py<\/p>\n<p>\u2502   \u2514\u2500\u2500 m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/p>\n<p>\u251c\u2500\u2500 tests\/<\/p>\n<p>\u251c\u2500\u2500 requirements.txt<\/p>\n<p>\u2514\u2500\u2500 README.md<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4e3b\u7a0b\u5e8f\u6587\u4ef6<\/strong>  <\/p>\n<\/p>\n<ul>\n<li><code>main.py<\/code>\u662f\u9879\u76ee\u7684\u5165\u53e3\u6587\u4ef6\uff0c\u901a\u5e38\u5305\u542b\u7a0b\u5e8f\u7684\u4e3b\u8981\u903b\u8f91\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h2>\u4e94\u3001\u542f\u52a8\u9879\u76ee<\/h2>\n<\/p>\n<p><p>\u542f\u52a8\u9879\u76ee\u901a\u5e38\u901a\u8fc7\u8fd0\u884c\u5165\u53e3\u6587\u4ef6\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8fd0\u884c\u7a0b\u5e8f<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u5bfc\u822a\u5230\u9879\u76ee\u7684\u6839\u76ee\u5f55\uff0c\u8fd0\u884c<code>python src\/main.py<\/code>\u542f\u52a8\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8c03\u8bd5\u548c\u6d4b\u8bd5<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u9891\u7e41\u8c03\u8bd5\u548c\u6d4b\u8bd5\u4ee3\u7801\uff0c\u4ee5\u786e\u4fdd\u529f\u80fd\u7684\u6b63\u786e\u6027\u548c\u6027\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h2>\u516d\u3001\u6269\u5c55\u548c\u4f18\u5316<\/h2>\n<\/p>\n<p><p>\u6839\u636e\u9879\u76ee\u7684\u9700\u8981\uff0c\u60a8\u53ef\u80fd\u8fd8\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u6269\u5c55\u548c\u4f18\u5316\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528IDE<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u5982PyCharm\u3001VSCode\u7b49\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ee3\u7801\u4f18\u5316<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f18\u5316\u4ee3\u7801\u7ed3\u6784\u548c\u903b\u8f91\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7248\u672c\u63a7\u5236<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528Git\u7b49\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u7ba1\u7406\u9879\u76ee\u4ee3\u7801\u7684\u53d8\u66f4\u548c\u534f\u4f5c\u5f00\u53d1\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h2>\u4e03\u3001\u90e8\u7f72\u548c\u53d1\u5e03<\/h2>\n<\/p>\n<p><p>\u5b8c\u6210\u5f00\u53d1\u540e\uff0c\u60a8\u9700\u8981\u5c06\u9879\u76ee\u90e8\u7f72\u5230\u670d\u52a1\u5668\u6216\u53d1\u5e03\u7ed9\u7528\u6237\u4f7f\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5305\u9879\u76ee<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u5de5\u5177\u5982<code>pyinstaller<\/code>\u6253\u5305\u9879\u76ee\uff0c\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u90e8\u7f72\u5230\u670d\u52a1\u5668<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u6839\u636e\u9879\u76ee\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u670d\u52a1\u5668\u73af\u5883\uff08\u5982AWS\u3001Heroku\u7b49\uff09\u8fdb\u884c\u90e8\u7f72\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6301\u7eed\u96c6\u6210\u548c\u4ea4\u4ed8<\/strong>  <\/p>\n<\/p>\n<ul>\n<li>\u8bbe\u7f6e<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\u6d41\u6c34\u7ebf\uff0c\u81ea\u52a8\u5316\u6d4b\u8bd5\u548c\u53d1\u5e03\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u4ea4\u4ed8\u6548\u7387\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6210\u529f\u8fd0\u884c\u5e76\u7ba1\u7406\u4e00\u4e2aPython\u9879\u76ee\u3002\u826f\u597d\u7684\u5f00\u53d1\u4e60\u60ef\u548c\u5de5\u5177\u4f7f\u7528\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u9879\u76ee\u7684\u8d28\u91cf\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728IDEA\u4e2d\u914d\u7f6ePython\u73af\u5883\u4ee5\u8fd0\u884c\u9879\u76ee\uff1f<\/strong><br \/>\u5728IDEA\u4e2d\u914d\u7f6ePython\u73af\u5883\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u5e76\u5728IDEA\u4e2d\u5b89\u88c5\u4e86Python\u63d2\u4ef6\u3002\u63a5\u4e0b\u6765\uff0c\u6253\u5f00IDEA\uff0c\u70b9\u51fb\u201cFile\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cProject Structure\u201d\uff0c\u5728\u201cSDKs\u201d\u9009\u9879\u4e2d\u6dfb\u52a0Python SDK\u3002\u5b8c\u6210\u540e\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\u6216\u5bfc\u5165\u73b0\u6709\u9879\u76ee\u3002\u6b64\u65f6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u53f3\u952e\u70b9\u51fb\u6587\u4ef6\u5e76\u9009\u62e9\u201cRun\u201d\u6765\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<p><strong>IDEA\u652f\u6301\u54ea\u4e9bPython\u6846\u67b6\u548c\u5e93\uff1f<\/strong><br \/>IDEA\u652f\u6301\u591a\u79cdPython\u6846\u67b6\u548c\u5e93\uff0c\u5305\u62ecFlask\u3001Django\u3001Pandas\u3001NumPy\u7b49\u3002\u901a\u8fc7IDEA\u7684\u63d2\u4ef6\u5e02\u573a\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u8fd9\u4e9b\u6846\u67b6\u7684\u652f\u6301\u3002IDEA\u8fd8\u63d0\u4f9b\u4e86\u667a\u80fd\u4ee3\u7801\u8865\u5168\u548c\u8c03\u8bd5\u5de5\u5177\uff0c\u5e2e\u52a9\u60a8\u66f4\u9ad8\u6548\u5730\u5f00\u53d1Python\u5e94\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3IDEA\u4e2dPython\u9879\u76ee\u8fd0\u884c\u65f6\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5982\u679c\u5728IDEA\u4e2d\u8fd0\u884cPython\u9879\u76ee\u65f6\u9047\u5230\u9519\u8bef\uff0c\u9996\u5148\u68c0\u67e5Python\u89e3\u91ca\u5668\u7684\u914d\u7f6e\u662f\u5426\u6b63\u786e\u3002\u786e\u4fdd\u6240\u9700\u7684\u5e93\u5df2\u5b89\u88c5\uff0c\u5e76\u4e14\u9879\u76ee\u7684\u4f9d\u8d56\u9879\u5728\u201crequirements.txt\u201d\u4e2d\u5217\u51fa\u3002\u60a8\u8fd8\u53ef\u4ee5\u67e5\u770bIDEA\u7684\u201cRun\u201d\u7a97\u53e3\u4e2d\u7684\u9519\u8bef\u65e5\u5fd7\uff0c\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3002\u5982\u679c\u95ee\u9898\u4ecd\u7136\u5b58\u5728\uff0c\u8003\u8651\u5728\u793e\u533a\u8bba\u575b\u6216Stack Overflow\u4e0a\u5bfb\u6c42\u5e2e\u52a9\uff0c\u901a\u5e38\u53ef\u4ee5\u627e\u5230\u89e3\u51b3\u65b9\u6848\u6216\u7c7b\u4f3c\u95ee\u9898\u7684\u8ba8\u8bba\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u8fd0\u884cPython\u9879\u76ee\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u4f9d\u8d56\u5e93\u3001\u914d\u7f6e\u9879\u76ee\u7ed3\u6784\u548c\u542f\u52a8\u9879\u76ee\u3002 \u5728 [&hellip;]","protected":false},"author":3,"featured_media":968465,"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\/968456"}],"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=968456"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/968456\/revisions"}],"predecessor-version":[{"id":968467,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/968456\/revisions\/968467"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/968465"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=968456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=968456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=968456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}