{"id":964510,"date":"2024-12-27T04:29:04","date_gmt":"2024-12-26T20:29:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/964510.html"},"modified":"2024-12-27T04:29:07","modified_gmt":"2024-12-26T20:29:07","slug":"%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80python%e7%9a%84%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/964510.html","title":{"rendered":"\u5982\u4f55\u6253\u5f00python\u7684\u811a\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181252\/cb82e4f1-dcac-468b-9475-479d1ed1c647.webp\" alt=\"\u5982\u4f55\u6253\u5f00python\u7684\u811a\u672c\" \/><\/p>\n<p><p> <strong>\u6253\u5f00Python\u811a\u672c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u6587\u672c\u7f16\u8f91\u5668\u7b49\u3002\u4ee5\u547d\u4ee4\u884c\u65b9\u5f0f\u4e3a\u4f8b\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u547d\u4ee4<code>python script_name.py<\/code>\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u4f7f\u7528IDE\uff0c\u5982PyCharm\u6216Visual Studio Code\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5982\u8c03\u8bd5\u548c\u4ee3\u7801\u8865\u5168\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u547d\u4ee4\u884c\u65b9\u5f0f\u6253\u5f00Python\u811a\u672c<\/p>\n<\/p>\n<p><p>\u547d\u4ee4\u884c\u662f\u4e00\u79cd\u76f4\u63a5\u800c\u7b80\u5355\u7684\u65b9\u5f0f\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u65e0\u8bba\u662f\u5728Windows\u3001macOS\u8fd8\u662fLinux\u7cfb\u7edf\u4e0a\uff0c\u4f60\u90fd\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u6267\u884cPython\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u6309\u4e0b\u201cWin + R\u201d\u952e\uff0c\u8f93\u5165\u201ccmd\u201d\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u4ee5\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5728macOS\u6216Linux\u4e0a\uff0c\u627e\u5230\u201cTerminal\u201d\u5e94\u7528\u7a0b\u5e8f\u5e76\u6253\u5f00\u5b83\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u201ccd\u201d\u547d\u4ee4\u5bfc\u822a\u5230Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u811a\u672c\u5b58\u653e\u5728\u684c\u9762\u4e0a\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u8f93\u5165\u201ccd Desktop\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u8f93\u5165\u201cpython script_name.py\u201d\u6765\u6267\u884c\u811a\u672c\u3002\u8bf7\u786e\u4fdd\u201cscript_name.py\u201d\u662f\u4f60\u7684Python\u6587\u4ef6\u7684\u540d\u79f0\u3002\u5982\u679c\u4f60\u5b89\u88c5\u4e86Python 3.x\u7248\u672c\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u201cpython3 script_name.py\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/p>\n<\/p>\n<p><p>\u4f7f\u7528IDE\u53ef\u4ee5\u63d0\u4f9b\u66f4\u76f4\u89c2\u7684\u7f16\u7a0b\u4f53\u9a8c\uff0c\u63d0\u4f9b\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u7248\u672c\u63a7\u5236\u7b49\u591a\u79cd\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong><\/p>\n<\/p>\n<p><p>PyCharm\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python IDE\uff0c\u63d0\u4f9b\u5b8c\u6574\u7684\u5f00\u53d1\u5de5\u5177\u96c6\u3002\u6253\u5f00PyCharm\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u6216\u5bfc\u5165\u73b0\u6709\u9879\u76ee\uff0c\u7136\u540e\u5728\u9879\u76ee\u7ed3\u6784\u4e2d\u627e\u5230\u5e76\u6253\u5f00\u4f60\u7684Python\u811a\u672c\u3002\u70b9\u51fb\u201cRun\u201d\u6309\u94ae\u6765\u6267\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong><\/p>\n<\/p>\n<p><p>Visual Studio Code\u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u5b89\u88c5Python\u6269\u5c55\u540e\uff0c\u6253\u5f00\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201cRun\u201d\u6309\u94ae\u6216\u4f7f\u7528\u5feb\u6377\u952e\u201cF5\u201d\u6765\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u7b80\u5355\u7684\u811a\u672c\uff0c\u6587\u672c\u7f16\u8f91\u5668\u4e5f\u53ef\u4ee5\u7528\u6765\u6253\u5f00\u548c\u7f16\u8f91Python\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Sublime Text<\/strong><\/p>\n<\/p>\n<p><p>Sublime Text\u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684\u6587\u672c\u7f16\u8f91\u5668\u3002\u4f60\u53ef\u4ee5\u7528\u5b83\u6253\u5f00Python\u811a\u672c\u5e76\u8fdb\u884c\u7f16\u8f91\u3002\u867d\u7136\u5b83\u672c\u8eab\u4e0d\u652f\u6301\u76f4\u63a5\u8fd0\u884c\u811a\u672c\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5\u63d2\u4ef6\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Notepad++<\/strong><\/p>\n<\/p>\n<p><p>Notepad++\u662fWindows\u7528\u6237\u5e38\u7528\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u7684\u8bed\u6cd5\u9ad8\u4eae\u3002\u6253\u5f00\u4f60\u7684Python\u811a\u672c\u8fdb\u884c\u67e5\u770b\u548c\u7f16\u8f91\uff0c\u4f46\u4f60\u9700\u8981\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528Jupyter Notebook<\/p>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u4ea4\u4e92\u5f0f\u8ba1\u7b97\u73af\u5883\uff0c\u7279\u522b\u9002\u5408\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Jupyter<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\u201cpip install jupyter\u201d\u6765\u5b89\u88c5Jupyter Notebook\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8Jupyter Notebook<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u201cjupyter notebook\u201d\u542f\u52a8\u670d\u52a1\u5668\uff0c\u5e76\u5728\u6d4f\u89c8\u5668\u4e2d\u81ea\u52a8\u6253\u5f00Jupyter\u754c\u9762\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u6216\u6253\u5f00Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728Jupyter\u754c\u9762\u4e2d\uff0c\u53ef\u4ee5\u65b0\u5efa\u4e00\u4e2aPython\u7b14\u8bb0\u672c\u6216\u6253\u5f00\u5df2\u6709\u7684\u7b14\u8bb0\u672c\u6587\u4ef6\u8fdb\u884c\u7f16\u8f91\u548c\u8fd0\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u8fd0\u884cPython\u811a\u672c\u3002\u901a\u5e38\uff0c\u8fd9\u9700\u8981\u901a\u8fc7SSH\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528SSH\u8fde\u63a5\u5230\u670d\u52a1\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\u201cssh user@server_address\u201d\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5e76\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u201ccd\u201d\u547d\u4ee4\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55\uff0c\u7136\u540e\u4f7f\u7528\u201cpython script_name.py\u201d\u547d\u4ee4\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u4f7f\u7528Python\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5305\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u8fd0\u884c\u201cpython -m venv env_name\u201d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u8fd0\u884c\u201cenv_name\\Scripts\\activate\u201d\uff1b\u5728macOS\u6216Linux\u4e0a\uff0c\u8fd0\u884c\u201csource env_name\/bin\/activate\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u6fc0\u6d3b\u72b6\u6001\u4e0b\uff0c\u8fd0\u884c\u201cpython script_name.py\u201d\u6765\u6267\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u3001IDE\u3001\u6587\u672c\u7f16\u8f91\u5668\uff0c\u8fd8\u662f\u5176\u4ed6\u5de5\u5177\u6253\u5f00Python\u811a\u672c\uff0c\u90fd\u6709\u5176\u5404\u81ea\u7684\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u5728\u9009\u62e9\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\u65f6\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u5f00\u53d1\u73af\u5883\u6765\u51b3\u5b9a\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u4e86\u89e3\u5176\u57fa\u672c\u64cd\u4f5c\u6b65\u9aa4\u548c\u4f18\u52bf\uff0c\u5c06\u6709\u52a9\u4e8e\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u6253\u5f00\u548c\u8fd0\u884cPython\u811a\u672c\uff0c\u5e76\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u65b9\u6cd5\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\u6253\u5f00Python\u811a\u672c\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u6253\u5f00Python\u811a\u672c\u3002\u9996\u5148\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165<code>python script.py<\/code>\u6765\u8fd0\u884c\u811a\u672c\u3002\u5728Mac\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u7ec8\u7aef\uff0c\u7c7b\u4f3c\u5730\u901a\u8fc7<code>cd<\/code>\u547d\u4ee4\u5207\u6362\u76ee\u5f55\uff0c\u5e76\u4f7f\u7528<code>python3 script.py<\/code>\u547d\u4ee4\u6765\u6267\u884c\u811a\u672c\u3002<\/p>\n<p><strong>\u6253\u5f00Python\u811a\u672c\u7684\u6700\u4f73\u7f16\u8f91\u5668\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u6709\u591a\u79cd\u7f16\u8f91\u5668\u53ef\u4ee5\u7528\u6765\u6253\u5f00\u548c\u7f16\u8f91Python\u811a\u672c\uff0c\u5305\u62ecPyCharm\u3001VS Code\u3001Sublime Text\u548cAtom\u7b49\u3002\u8fd9\u4e9b\u7f16\u8f91\u5668\u63d0\u4f9b\u4e86\u4ee3\u7801\u9ad8\u4eae\u3001\u81ea\u52a8\u5b8c\u6210\u548c\u8c03\u8bd5\u529f\u80fd\uff0c\u80fd\u591f\u5927\u5927\u63d0\u9ad8\u7f16\u7a0b\u6548\u7387\u3002\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u81ea\u5df1\u5de5\u4f5c\u6d41\u7a0b\u548c\u9700\u6c42\u7684\u7f16\u8f91\u5668\uff0c\u53ef\u4ee5\u8ba9\u7f16\u5199\u548c\u7ba1\u7406Python\u4ee3\u7801\u53d8\u5f97\u66f4\u52a0\u8f7b\u677e\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728IDE\u4e2d\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d\uff0c\u4f8b\u5982PyCharm\u6216Visual Studio Code\uff0c\u53ef\u4ee5\u76f4\u63a5\u6253\u5f00Python\u811a\u672c\u6587\u4ef6\u5e76\u4f7f\u7528\u5185\u7f6e\u7684\u8fd0\u884c\u6309\u94ae\u6765\u6267\u884c\u3002\u901a\u5e38\uff0cIDE\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u201c\u8fd0\u884c\u201d\u6216\u201c\u8c03\u8bd5\u201d\u9009\u9879\uff0c\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u5730\u5728\u73af\u5883\u4e2d\u6d4b\u8bd5\u548c\u8c03\u8bd5\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u5f0f\u7b80\u5316\u4e86\u547d\u4ee4\u884c\u64cd\u4f5c\uff0c\u4f7f\u5f97\u65b0\u624b\u7528\u6237\u66f4\u52a0\u5bb9\u6613\u4e0a\u624b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u6253\u5f00Python\u811a\u672c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u6587\u672c\u7f16\u8f91\u5668\u7b49\u3002\u4ee5\u547d\u4ee4\u884c\u65b9\u5f0f\u4e3a\u4f8b\uff0c\u4f60\u53ef [&hellip;]","protected":false},"author":3,"featured_media":964514,"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\/964510"}],"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=964510"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964510\/revisions"}],"predecessor-version":[{"id":964517,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964510\/revisions\/964517"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/964514"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=964510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=964510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=964510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}