{"id":956629,"date":"2024-12-27T02:39:04","date_gmt":"2024-12-26T18:39:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/956629.html"},"modified":"2024-12-27T02:39:06","modified_gmt":"2024-12-26T18:39:06","slug":"%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8cpython%e8%84%9a%e6%9c%ac%e8%a7%86%e9%a2%91","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/956629.html","title":{"rendered":"\u5982\u4f55\u8fd0\u884cpython\u811a\u672c\u89c6\u9891"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100217\/3a9486a0-f0dc-46aa-a108-aea01d73d88c.webp\" alt=\"\u5982\u4f55\u8fd0\u884cpython\u811a\u672c\u89c6\u9891\" \/><\/p>\n<p><p> <strong>\u8fd0\u884cPython\u811a\u672c\u7684\u89c6\u9891\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u3001\u4f7f\u7528Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u4f7f\u7528\u5728\u7ebfPython\u89e3\u91ca\u5668\u3002<\/strong>\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u8fd0\u884c\uff0c\u6b65\u9aa4\u7b80\u4fbf\u4e14\u6548\u7387\u9ad8\u3002\u8be6\u7ec6\u6765\u8bf4\uff0c\u9996\u5148\u786e\u4fdd\u5df2\u5b89\u88c5Python\uff0c\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u5305\u542bPython\u811a\u672c\u7684\u76ee\u5f55\uff0c\u8f93\u5165<code>python script_name.py<\/code>\u5373\u53ef\u8fd0\u884c\u811a\u672c\u3002\u4f7f\u7528Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001VSCode\u7b49\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u5f3a\u5927\u7684\u8c03\u8bd5\u529f\u80fd\u548c\u4ee3\u7801\u7ba1\u7406\u3002\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u5728\u7ebfPython\u89e3\u91ca\u5668\uff0c\u8fd9\u5bf9\u4e8e\u65e0\u9700\u5b89\u88c5Python\u73af\u5883\u7684\u60c5\u51b5\u7279\u522b\u6709\u7528\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u8fd0\u884cPython\u811a\u672c\u662f\u6700\u76f4\u63a5\u548c\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong>\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\u3002\u53ef\u4ee5\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u547d\u4ee4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230\u811a\u672c\u76ee\u5f55<\/strong>\uff1a\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\u7528\u6237\u4f7f\u7528\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\uff0cMac\u548cLinux\u7528\u6237\u4f7f\u7528\u201c\u7ec8\u7aef\u201d\uff09\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u811a\u672c\u4f4d\u4e8e\u684c\u9762\uff0c\u53ef\u4ee5\u8f93\u5165<code>cd Desktop<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u811a\u672c<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python script_name.py<\/code>\uff0c\u5176\u4e2d<code>script_name.py<\/code>\u662f\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\u540d\u3002\u6309\u4e0b\u56de\u8f66\u952e\uff0cPython\u89e3\u91ca\u5668\u5c06\u5f00\u59cb\u6267\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u786e\u4fdd\u811a\u672c\u6587\u4ef6\u7684\u6269\u5c55\u540d\u4e3a<code>.py<\/code>\uff0c\u4e14\u6587\u4ef6\u7f16\u7801\u683c\u5f0f\u4e0ePython\u7248\u672c\u517c\u5bb9\u3002\u5982\u679c\u4f7f\u7528\u7684\u662fPython 3\uff0c\u786e\u4fdd\u811a\u672c\u4e2d\u6ca1\u6709Python 2\u7279\u6709\u7684\u8bed\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/p>\n<\/p>\n<p><p>Python IDE\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5982\u8bed\u6cd5\u9ad8\u4eae\u3001\u81ea\u52a8\u8865\u5168\u548c\u8c03\u8bd5\u5de5\u5177\uff0c\u8fd9\u5bf9\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u662f\u975e\u5e38\u6709\u5e2e\u52a9\u7684\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u4e00\u4e2aIDE<\/strong>\uff1a\u5e38\u7528\u7684Python IDE\u5305\u62ecPyCharm\u3001Visual Studio Code\u3001Jupyter Notebook\u7b49\u3002\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u4f60\u9700\u6c42\u7684IDE\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u548c\u914d\u7f6e<\/strong>\uff1a\u4e0b\u8f7d\u5e76\u5b89\u88c5IDE\uff0c\u786e\u4fddPython\u89e3\u91ca\u5668\u8def\u5f84\u5df2\u6b63\u786e\u914d\u7f6e\u3002\u6709\u4e9bIDE\u5982PyCharm\u4f1a\u81ea\u52a8\u68c0\u6d4bPython\u73af\u5883\uff0c\u800c\u5728VSCode\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u624b\u52a8\u8bbe\u7f6ePython\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u6216\u6253\u5f00Python\u811a\u672c<\/strong>\uff1a\u5728IDE\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\u6216\u8005\u6253\u5f00\u5df2\u6709\u7684Python\u811a\u672c\u6587\u4ef6\u3002IDE\u901a\u5e38\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u6587\u4ef6\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5feb\u901f\u5b9a\u4f4d\u5230\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u548c\u8c03\u8bd5<\/strong>\uff1a\u5927\u591a\u6570IDE\u90fd\u6709\u201c\u8fd0\u884c\u201d\u6309\u94ae\uff0c\u70b9\u51fb\u5373\u53ef\u6267\u884c\u811a\u672c\u3002\u4f60\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\uff0c\u9010\u6b65\u8c03\u8bd5\u4ee3\u7801\uff0c\u67e5\u770b\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p><strong>\u4f18\u52bf<\/strong>\uff1a\u4f7f\u7528IDE\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7f16\u5199\u6548\u7387\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5927\u578b\u9879\u76ee\u548c\u9700\u8981\u9891\u7e41\u8c03\u8bd5\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u5728\u7ebfPython\u89e3\u91ca\u5668<\/p>\n<\/p>\n<p><p>\u5728\u7ebfPython\u89e3\u91ca\u5668\u662f\u65e0\u9700\u672c\u5730\u5b89\u88c5Python\u73af\u5883\u7684\u4e00\u79cd\u4fbf\u6377\u9009\u62e9\uff0c\u5c24\u5176\u9002\u5408\u6d4b\u8bd5\u5c0f\u6bb5\u4ee3\u7801\u6216\u5728\u65e0\u6cd5\u5b89\u88c5\u8f6f\u4ef6\u7684\u73af\u5883\u4e2d\u4f7f\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u5728\u7ebf\u89e3\u91ca\u5668<\/strong>\uff1a\u6709\u8bb8\u591a\u5728\u7ebfPython\u89e3\u91ca\u5668\u53ef\u4f9b\u9009\u62e9\uff0c\u5982Repl.it\u3001Google Colab\u3001PythonAnywhere\u7b49\u3002\u8fd9\u4e9b\u5e73\u53f0\u901a\u5e38\u652f\u6301Python 3\uff0c\u5e76\u63d0\u4f9b\u57fa\u672c\u7684\u6587\u4ef6\u7ba1\u7406\u548c\u4ee3\u7801\u6267\u884c\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199\u4ee3\u7801<\/strong>\uff1a\u5728\u5728\u7ebf\u89e3\u91ca\u5668\u7684\u7f16\u8f91\u7a97\u53e3\u4e2d\u7f16\u5199\u6216\u7c98\u8d34\u4f60\u7684Python\u4ee3\u7801\u3002\u8fd9\u4e9b\u5e73\u53f0\u901a\u5e38\u63d0\u4f9b\u4ee3\u7801\u9ad8\u4eae\u548c\u57fa\u672c\u7684\u4ee3\u7801\u5efa\u8bae\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u4ee3\u7801<\/strong>\uff1a\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\u5373\u53ef\u6267\u884c\u4ee3\u7801\u3002\u5728\u7ebf\u89e3\u91ca\u5668\u901a\u5e38\u4f1a\u5728\u9875\u9762\u4e0b\u65b9\u6216\u53f3\u4fa7\u663e\u793a\u8f93\u51fa\u7ed3\u679c\u548c\u4efb\u4f55\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u5728\u7ebf\u89e3\u91ca\u5668\u9002\u5408\u7528\u4e8e\u6559\u5b66\u3001\u5feb\u901f\u6d4b\u8bd5\u548c\u65e0\u6cd5\u4f7f\u7528\u672c\u5730\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\u6765\u8bf4\uff0c\u8fd0\u884cPython\u811a\u672c\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u5f0f\u53d6\u51b3\u4e8e\u7528\u6237\u7684\u5177\u4f53\u9700\u6c42\u548c\u4f7f\u7528\u573a\u666f\u3002\u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u4e00\u79cd\u76f4\u63a5\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u800c\u5bf9\u4e8e\u9700\u8981\u66f4\u591a\u529f\u80fd\u7684\u5f00\u53d1\u8005\uff0cIDE\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002\u5728\u7ebf\u89e3\u91ca\u5668\u5219\u4e3a\u90a3\u4e9b\u9700\u8981\u968f\u65f6\u968f\u5730\u8fd0\u884cPython\u4ee3\u7801\u7684\u4eba\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u719f\u7ec3\u638c\u63e1\u8fd9\u4e9b\u5de5\u5177\u548c\u73af\u5883\u7684\u4f7f\u7528\u90fd\u662f\u63d0\u5347Python\u5f00\u53d1\u6548\u7387\u7684\u5173\u952e\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\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728Windows\u3001macOS\u548cLinux\u4e0a\u8fd0\u884cPython\u811a\u672c\u7684\u65b9\u6cd5\u7565\u6709\u4e0d\u540c\u3002\u5728Windows\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u63d0\u793a\u7b26\u6216PowerShell\uff0c\u9996\u5148\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55\uff0c\u8f93\u5165<code>python script_name.py<\/code>\u6765\u8fd0\u884c\u3002\u5728macOS\u548cLinux\u4e0a\uff0c\u6253\u5f00\u7ec8\u7aef\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5b9a\u4f4d\u5230\u811a\u672c\u76ee\u5f55\u540e\uff0c\u540c\u6837\u8f93\u5165<code>python script_name.py<\/code>\u5373\u53ef\u3002\u786e\u4fdd\u5728\u8fd0\u884c\u4e4b\u524d\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u73af\u5883\u3002<\/p>\n<p><strong>\u8fd0\u884cPython\u811a\u672c\u65f6\u5e38\u89c1\u7684\u9519\u8bef\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u201cSyntaxError: invalid syntax\u201d\uff0c\u901a\u5e38\u662f\u56e0\u4e3a\u4ee3\u7801\u4e2d\u6709\u62fc\u5199\u9519\u8bef\u6216\u683c\u5f0f\u95ee\u9898\u3002\u53e6\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u201cModuleNotFoundError\u201d\uff0c\u8fd9\u8868\u660e\u60a8\u8bd5\u56fe\u5bfc\u5165\u7684\u6a21\u5757\u672a\u5b89\u88c5\u6216\u672a\u627e\u5230\u3002\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u5e93\u90fd\u5df2\u5b89\u88c5\uff0c\u5e76\u4ed4\u7ec6\u68c0\u67e5\u4ee3\u7801\u4ee5\u907f\u514d\u8bed\u6cd5\u9519\u8bef\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\u8fd0\u884cPython\u811a\u672c\u901a\u5e38\u66f4\u4e3a\u7b80\u4fbf\u3002\u5927\u591a\u6570IDE\uff08\u5982PyCharm\u3001VS Code\u7b49\uff09\u63d0\u4f9b\u4e86\u76f4\u63a5\u8fd0\u884c\u811a\u672c\u7684\u529f\u80fd\u3002\u60a8\u53ea\u9700\u6253\u5f00\u811a\u672c\u6587\u4ef6\uff0c\u7136\u540e\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\uff0c\u6216\u8005\u4f7f\u7528\u5feb\u6377\u952e\uff08\u5982Shift + F10\uff09\uff0cIDE\u4f1a\u81ea\u52a8\u5904\u7406Python\u89e3\u91ca\u5668\u7684\u8c03\u7528\u548c\u73af\u5883\u8bbe\u7f6e\uff0c\u8ba9\u60a8\u4e13\u6ce8\u4e8e\u4ee3\u7801\u5f00\u53d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8fd0\u884cPython\u811a\u672c\u7684\u89c6\u9891\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u3001\u4f7f\u7528Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":956632,"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\/956629"}],"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=956629"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/956629\/revisions"}],"predecessor-version":[{"id":956636,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/956629\/revisions\/956636"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/956632"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=956629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=956629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=956629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}