{"id":927482,"date":"2024-12-26T16:10:34","date_gmt":"2024-12-26T08:10:34","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/927482.html"},"modified":"2024-12-26T16:10:36","modified_gmt":"2024-12-26T08:10:36","slug":"python%e5%a6%82%e4%bd%95%e6%89%a7%e8%a1%8cpython%e8%84%9a%e6%9c%ac%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/927482.html","title":{"rendered":"python\u5982\u4f55\u6267\u884cpython\u811a\u672c\u547d\u4ee4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25063605\/c51ae697-cf4e-4863-8217-b2ad2a342855.webp\" alt=\"python\u5982\u4f55\u6267\u884cpython\u811a\u672c\u547d\u4ee4\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u6267\u884cPython\u811a\u672c\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u901a\u8fc7IDE\u3001\u5229\u7528\u811a\u672c\u8c03\u7528\u3001\u5d4c\u5165Python\u4ee3\u7801\u7b49\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u6267\u884cPython\u811a\u672c\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u8fd0\u884c\u5e76\u6d4b\u8bd5\u4ee3\u7801\uff0c\u7279\u522b\u662f\u5728\u5f00\u53d1\u548c\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u4ecb\u7ecd\u5982\u4f55\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u6267\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u6267\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u6267\u884cPython\u811a\u672c\u7684\u6700\u57fa\u672c\u65b9\u6cd5\u3002\u60a8\u53ea\u9700\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\uff0c\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u5e76\u8f93\u5165\u76f8\u5e94\u7684\u547d\u4ee4\u5373\u53ef\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u641c\u7d22\u201ccmd\u201d\u6765\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5728Mac\u548cLinux\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6253\u5f00\u201c\u7ec8\u7aef\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230\u811a\u672c\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u5b58\u653ePython\u811a\u672c\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u811a\u672c\u4f4d\u4e8e\u201cC:\\Scripts\u201d\u76ee\u5f55\u4e2d\uff0c\u60a8\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd C:\\Scripts<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff08\u89c6\u60a8\u7684Python\u7248\u672c\u800c\u5b9a\uff09\uff0c\u7136\u540e\u8ddf\u4e0a\u811a\u672c\u6587\u4ef6\u540d\u3002\u4f8b\u5982\uff0c\u8981\u8fd0\u884c\u540d\u4e3a<code>myscript.py<\/code>\u7684\u811a\u672c\uff0c\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python myscript.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fPython 3\uff0c\u53ef\u80fd\u9700\u8981\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 myscript.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u901a\u8fc7IDE\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u8bb8\u591a\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u63d0\u4f9b\u4e86\u76f4\u63a5\u8fd0\u884cPython\u811a\u672c\u7684\u529f\u80fd\uff0c\u8fd9\u5bf9\u4e8e\u5f00\u53d1\u548c\u8c03\u8bd5\u975e\u5e38\u6709\u7528\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\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002\u8981\u5728PyCharm\u4e2d\u8fd0\u884c\u811a\u672c\uff0c\u60a8\u53ef\u4ee5\u6253\u5f00\u9879\u76ee\u5e76\u627e\u5230\u8981\u8fd0\u884c\u7684\u811a\u672c\u6587\u4ef6\uff0c\u7136\u540e\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\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\u79cd\u6d41\u884c\u7684\u9009\u62e9\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u8f7b\u91cf\u7ea7\u9879\u76ee\u3002\u5b89\u88c5Python\u6269\u5c55\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u811a\u672c\u3002\u53ea\u9700\u6253\u5f00\u811a\u672c\u6587\u4ef6\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201c\u8fd0\u884c\u201d\u6309\u94ae\u6216\u6309\u4e0b\u5feb\u6377\u952e<code>Ctrl + F5<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Jupyter Notebook<\/strong><\/p>\n<\/p>\n<p><p>Jupyter Notebook\u9002\u7528\u4e8e\u4ea4\u4e92\u5f0f\u5f00\u53d1\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u5206\u6790\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9879\u76ee\u4e2d\u3002\u60a8\u53ef\u4ee5\u5728Notebook\u4e2d\u9010\u6b65\u8fd0\u884c\u4ee3\u7801\u5355\u5143\u683c\uff0c\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u6d4b\u8bd5\u548c\u67e5\u770b\u8f93\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5229\u7528\u811a\u672c\u8c03\u7528\u5176\u4ed6Python\u811a\u672c<\/p>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5728\u4e00\u4e2aPython\u811a\u672c\u4e2d\u8c03\u7528\u53e6\u4e00\u4e2a\u811a\u672c\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7<code>import<\/code>\u8bed\u53e5\u5b9e\u73b0\uff0c\u6216\u8005\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u6765\u6267\u884c\u53e6\u4e00\u4e2a\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528<code>import<\/code>\u8bed\u53e5<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u8981\u5728\u4e00\u4e2a\u811a\u672c\u4e2d\u8c03\u7528\u53e6\u4e00\u4e2a\u811a\u672c\u7684\u51fd\u6570\u6216\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u60a8\u6709\u4e24\u4e2a\u811a\u672c<code>m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/code>\u548c<code>utils.py<\/code>\uff0c\u53ef\u4ee5\u5728<code>main.py<\/code>\u4e2d\u5bfc\u5165<code>utils.py<\/code>\u4e2d\u7684\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># utils.py<\/p>\n<p>def hello_world():<\/p>\n<p>    print(&quot;Hello, world!&quot;)<\/p>\n<h2><strong>main.py<\/strong><\/h2>\n<p>import utils<\/p>\n<p>utils.hello_world()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u9700\u8981\u5728\u4e00\u4e2a\u811a\u672c\u4e2d\u6267\u884c\u53e6\u4e00\u4e2a\u72ec\u7acb\u7684Python\u811a\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u3002\u5b83\u5141\u8bb8\u60a8\u5728Python\u4e2d\u6267\u884c\u5916\u90e8\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import subprocess<\/p>\n<p>subprocess.run([&quot;python&quot;, &quot;another_script.py&quot;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5d4c\u5165Python\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5728\u53e6\u4e00\u4e2a\u7f16\u7a0b\u8bed\u8a00\u7684\u9879\u76ee\u4e2d\u5d4c\u5165Python\u4ee3\u7801\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u5305\u62ec\u4f7f\u7528C\/C++\u4e2d\u7684Python C API\u3001\u4f7f\u7528Java\u4e2d\u7684Jython\uff0c\u6216\u4f7f\u7528.NET\u4e2d\u7684IronPython\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528Python C API<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u5728C\/C++\u7a0b\u5e8f\u4e2d\u5d4c\u5165Python\u89e3\u91ca\u5668\uff0c\u4f7f\u7528Python C API\u6765\u6267\u884cPython\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5728\u9ad8\u6027\u80fd\u5e94\u7528\u4e2d\u96c6\u6210Python\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;Python.h&gt;<\/p>\n<p>int main() {<\/p>\n<p>    Py_Initialize();<\/p>\n<p>    PyRun_SimpleString(&quot;print(&#39;Hello, World!&#39;)&quot;);<\/p>\n<p>    Py_Finalize();<\/p>\n<p>    return 0;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Jython<\/strong><\/p>\n<\/p>\n<p><p>Jython\u662fPython\u7684Java\u5b9e\u73b0\uff0c\u5141\u8bb8\u60a8\u5728Java\u7a0b\u5e8f\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u3002\u901a\u8fc7Jython\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Java\u9879\u76ee\u4e2d\u96c6\u6210Python\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528IronPython<\/strong><\/p>\n<\/p>\n<p><p>IronPython\u662fPython\u7684.NET\u5b9e\u73b0\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5728.NET\u5e73\u53f0\u4e0a\u8fd0\u884cPython\u4ee3\u7801\u7684\u573a\u666f\u3002\u5b83\u5141\u8bb8\u60a8\u5728.NET\u5e94\u7528\u4e2d\u8c03\u7528Python\u4ee3\u7801\uff0c\u5e76\u4e0eC#\u7b49\u8bed\u8a00\u65e0\u7f1d\u96c6\u6210\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u786e\u4fdd\u6bcf\u4e2a\u9879\u76ee\u72ec\u7acb\u4e8e\u7cfb\u7edf\u8303\u56f4\u7684Python\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u9996\u5148\uff0c\u5bfc\u822a\u5230\u9879\u76ee\u76ee\u5f55\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmyenv\u201d\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\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\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>\u5728Mac\u548cLinux\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u60a8\u53ef\u4ee5\u50cf\u5e73\u5e38\u4e00\u6837\u8fd0\u884cPython\u811a\u672c\u3002\u6b64\u65f6\uff0c\u6240\u6709\u5b89\u88c5\u7684\u4f9d\u8d56\u9879\u90fd\u5c06\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fdb\u884c\u7ba1\u7406\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u8303\u56f4\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u4f7f\u7528\u8c03\u5ea6\u7a0b\u5e8f\u81ea\u52a8\u6267\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5b9a\u671f\u6216\u6839\u636e\u7279\u5b9a\u4e8b\u4ef6\u81ea\u52a8\u6267\u884cPython\u811a\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u7684\u4efb\u52a1\u8c03\u5ea6\u7a0b\u5e8f\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u6765\u5b89\u6392Python\u811a\u672c\u7684\u6267\u884c\u3002\u6253\u5f00\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u4efb\u52a1\uff0c\u5e76\u6307\u5b9aPython\u811a\u672c\u7684\u8def\u5f84\u548c\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Cron\u4f5c\u4e1a<\/strong><\/p>\n<\/p>\n<p><p>\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528cron\u4f5c\u4e1a\u6765\u5b89\u6392\u811a\u672c\u7684\u6267\u884c\u3002\u4f7f\u7528<code>crontab -e<\/code>\u547d\u4ee4\u7f16\u8f91crontab\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4e00\u884c\u4ee5\u6307\u5b9a\u811a\u672c\u7684\u6267\u884c\u65f6\u95f4\u548c\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">0 0 * * * \/usr\/bin\/python \/path\/to\/script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u6bcf\u5929\u5348\u591c\u8fd0\u884c\u4e00\u6b21\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u4f7f\u7528Docker\u5bb9\u5668\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>Docker\u5bb9\u5668\u63d0\u4f9b\u4e86\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u65b9\u5f0f\u6765\u90e8\u7f72\u548c\u8fd0\u884cPython\u5e94\u7528\u3002\u901a\u8fc7Docker\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u6240\u6709\u4f9d\u8d56\u9879\u7684\u955c\u50cf\uff0c\u5e76\u5728\u4efb\u4f55\u652f\u6301Docker\u7684\u5e73\u53f0\u4e0a\u8fd0\u884c\u5b83\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efaDockerfile<\/strong><\/p>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2aDockerfile\u4ee5\u5b9a\u4e49Python\u5e94\u7528\u7684\u73af\u5883\u548c\u4f9d\u8d56\u9879\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-dockerfile\">FROM python:3.8-slim<\/p>\n<p>WORKDIR \/app<\/p>\n<p>COPY requirements.txt .\/<\/p>\n<p>RUN pip install --no-cache-dir -r requirements.txt<\/p>\n<p>COPY . .<\/p>\n<p>CMD [ &quot;python&quot;, &quot;.\/your-script.py&quot; ]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efaDocker\u955c\u50cf<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efaDocker\u955c\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker build -t your-image-name .<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cDocker\u5bb9\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884cDocker\u5bb9\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker run -d your-image-name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728\u5bb9\u5668\u4e2d\u6267\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u5404\u79cd\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u7075\u6d3b\u5730\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u6267\u884cPython\u811a\u672c\u3002\u65e0\u8bba\u662f\u672c\u5730\u5f00\u53d1\u3001\u751f\u4ea7\u90e8\u7f72\uff0c\u8fd8\u662f\u81ea\u52a8\u5316\u4efb\u52a1\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u652f\u6301\u6765\u6ee1\u8db3\u60a8\u7684\u9700\u6c42\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u4e3a\u60a8\u63d0\u4f9b\u6709\u7528\u7684\u6307\u5bfc\uff0c\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u6267\u884c\u548c\u7ba1\u7406Python\u811a\u672c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ea\u9700\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165\u547d\u4ee4<code>python your_script.py<\/code>\uff08\u5982\u679c\u662fPython 3\u5219\u4e3a<code>python3 your_script.py<\/code>\uff09\u3002\u786e\u4fdd\u4f60\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u5df2\u7ecf\u5305\u542b\u4e86Python\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u4ee5\u4fbf\u80fd\u591f\u76f4\u63a5\u8c03\u7528Python\u547d\u4ee4\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Windows\u4e0a\u4f7f\u7528Python\u547d\u4ee4\u884c\u8fd0\u884c\u811a\u672c\uff1f<\/strong><br \/>\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u6216PowerShell\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5207\u6362\u5230\u811a\u672c\u6587\u4ef6\u6240\u5728\u7684\u6587\u4ef6\u5939\uff0c\u7136\u540e\u8f93\u5165<code>python script_name.py<\/code>\u6765\u6267\u884c\u3002\u786e\u4fdd\u5728\u5b89\u88c5Python\u65f6\u9009\u62e9\u4e86\u201c\u5c06Python\u6dfb\u52a0\u5230\u7cfb\u7edf\u8def\u5f84\u201d\u7684\u9009\u9879\uff0c\u4ee5\u4fbf\u80fd\u591f\u5728\u4efb\u4f55\u4f4d\u7f6e\u8c03\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728IDE\u4e2d\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8bb8\u591a\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001Visual Studio Code\u6216Jupyter Notebook\u90fd\u63d0\u4f9b\u4e86\u76f4\u63a5\u8fd0\u884cPython\u811a\u672c\u7684\u529f\u80fd\u3002\u5728IDE\u4e2d\u6253\u5f00\u4f60\u7684\u811a\u672c\u6587\u4ef6\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u5de5\u5177\u680f\u4e0a\u7684\u201c\u8fd0\u884c\u201d\u6309\u94ae\u6216\u4f7f\u7528\u5feb\u6377\u952e\uff08\u5982F5\uff09\u6765\u6267\u884c\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u5f97\u8c03\u8bd5\u548c\u67e5\u770b\u8f93\u51fa\u53d8\u5f97\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6267\u884cPython\u811a\u672c\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u901a\u8fc7IDE\u3001\u5229\u7528\u811a\u672c\u8c03\u7528\u3001\u5d4c\u5165Python\u4ee3\u7801 [&hellip;]","protected":false},"author":3,"featured_media":927486,"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\/927482"}],"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=927482"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/927482\/revisions"}],"predecessor-version":[{"id":927488,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/927482\/revisions\/927488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/927486"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=927482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=927482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=927482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}