{"id":1180076,"date":"2025-01-15T18:32:26","date_gmt":"2025-01-15T10:32:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1180076.html"},"modified":"2025-01-15T18:32:29","modified_gmt":"2025-01-15T10:32:29","slug":"%e7%bc%96%e5%86%99%e5%ae%8cpython%e4%bb%a3%e7%a0%81%e5%a6%82%e4%bd%95%e5%af%bc%e5%87%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1180076.html","title":{"rendered":"\u7f16\u5199\u5b8cpython\u4ee3\u7801\u5982\u4f55\u5bfc\u51fa"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25114313\/5d243705-9661-4abd-b368-33bb12408d8e.webp\" alt=\"\u7f16\u5199\u5b8cpython\u4ee3\u7801\u5982\u4f55\u5bfc\u51fa\" \/><\/p>\n<p><p> \u7f16\u5199\u5b8cPython\u4ee3\u7801\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5bfc\u51fa\u4ee3\u7801\u6587\u4ef6\uff0c\u4ee5\u4fbf\u8fdb\u884c\u5206\u4eab\u3001\u5907\u4efd\u6216\u8005\u90e8\u7f72\u3002<strong>\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u4fdd\u5b58\u6587\u4ef6\u3001\u5c06\u4ee3\u7801\u5bfc\u51fa\u4e3a\u538b\u7f29\u5305\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3001\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5bfc\u51fa\u4e3aJupyter Notebook\u7b49<\/strong>\u3002\u8fd9\u91cc\u6211\u4eec\u5c06\u8be6\u7ec6\u8bb2\u89e3\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff1a<strong>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u4fdd\u5b58\u6587\u4ef6<\/strong>\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u4fdd\u5b58\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1Python\u4ee3\u7801\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6216\u8005\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u6765\u7f16\u5199\u4ee3\u7801\u3002\u5e38\u89c1\u7684\u6587\u672c\u7f16\u8f91\u5668\u5305\u62ecVS Code\u3001Sublime Text\u3001Atom\u7b49\uff0c\u800c\u5e38\u89c1\u7684IDE\u5219\u5305\u62ecPyCharm\u3001Anaconda\u7b49\u3002\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u4ee3\u7801\u4fdd\u5b58\u4e3a.py\u6587\u4ef6\u683c\u5f0f\uff0c\u4ece\u800c\u5bfc\u51fa\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00\u6587\u672c\u7f16\u8f91\u5668\u6216IDE<\/strong>\uff1a\u9996\u5148\u9700\u8981\u6253\u5f00\u4f60\u6240\u4f7f\u7528\u7684\u6587\u672c\u7f16\u8f91\u5668\u6216IDE\u3002<\/li>\n<li><strong>\u7f16\u5199\u6216\u5bfc\u5165\u4ee3\u7801<\/strong>\uff1a\u5728\u7f16\u8f91\u5668\u4e2d\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\uff0c\u6216\u8005\u5c06\u5df2\u6709\u7684\u4ee3\u7801\u7c98\u8d34\u5230\u7f16\u8f91\u5668\u4e2d\u3002<\/li>\n<li><strong>\u4fdd\u5b58\u4ee3\u7801\u6587\u4ef6<\/strong>\uff1a\u70b9\u51fb\u201c\u6587\u4ef6\u201d\u83dc\u5355\u4e2d\u7684\u201c\u4fdd\u5b58\u201d\u6216\u8005\u201c\u53e6\u5b58\u4e3a\u201d\u9009\u9879\uff0c\u9009\u62e9\u6587\u4ef6\u4fdd\u5b58\u4f4d\u7f6e\u5e76\u547d\u540d\u6587\u4ef6\uff0c\u786e\u4fdd\u6587\u4ef6\u6269\u5c55\u540d\u4e3a.py\u3002\u8fd9\u6837\uff0c\u4f60\u7684Python\u4ee3\u7801\u5c06\u88ab\u4fdd\u5b58\u4e3a\u4e00\u4e2a.py\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u662f\u4e00\u79cd\u57fa\u7840\u800c\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\u3002\u6b64\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5bfc\u51fa\u548c\u5171\u4eabPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf<\/p>\n<\/p>\n<p><p>\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08VCS\uff09\u5982Git\u3001Mercurial\u7b49\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7ba1\u7406\u4ee3\u7801\u7684\u7248\u672c\uff0c\u5e76\u4e0e\u56e2\u961f\u6210\u5458\u534f\u4f5c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Git\u5bfc\u51faPython\u4ee3\u7801\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5Git<\/strong>\uff1a\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u4e0a\u5df2\u5b89\u88c5Git\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>git --version<\/code>\u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u3002<\/li>\n<li><strong>\u521d\u59cb\u5316Git\u4ed3\u5e93<\/strong>\uff1a\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e0b\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165<code>git init<\/code>\u6765\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684Git\u4ed3\u5e93\u3002<\/li>\n<li><strong>\u6dfb\u52a0\u6587\u4ef6\u5230\u4ed3\u5e93<\/strong>\uff1a\u4f7f\u7528<code>git add .<\/code>\u547d\u4ee4\u5c06\u6240\u6709\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff0c\u6216\u8005\u4f7f\u7528<code>git add &lt;filename&gt;<\/code>\u6dfb\u52a0\u7279\u5b9a\u6587\u4ef6\u3002<\/li>\n<li><strong>\u63d0\u4ea4\u4ee3\u7801<\/strong>\uff1a\u4f7f\u7528<code>git commit -m &quot;Initial commit&quot;<\/code>\u547d\u4ee4\u5c06\u6682\u5b58\u533a\u7684\u6587\u4ef6\u63d0\u4ea4\u5230\u672c\u5730\u4ed3\u5e93\u3002<\/li>\n<li><strong>\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/strong>\uff1a\u5c06\u4ee3\u7801\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff08\u5982GitHub\u3001GitLab\u7b49\uff09\uff0c\u4f7f\u7528<code>git remote add origin &lt;repository_url&gt;<\/code>\u547d\u4ee4\u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\uff0c\u7136\u540e\u4f7f\u7528<code>git push -u origin master<\/code>\u63a8\u9001\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5171\u4eab\u4ee3\u7801\u3001\u7ba1\u7406\u7248\u672c\uff0c\u5e76\u4e0e\u56e2\u961f\u6210\u5458\u534f\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5bfc\u51fa\u4e3a\u538b\u7f29\u5305<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u6574\u4e2a\u9879\u76ee\u6253\u5305\u4e3a\u538b\u7f29\u6587\u4ef6\uff0c\u4ee5\u4fbf\u4e8e\u5206\u53d1\u548c\u5907\u4efd\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u9009\u62e9\u6587\u4ef6\u548c\u6587\u4ef6\u5939<\/strong>\uff1a\u5728\u6587\u4ef6\u7ba1\u7406\u5668\u4e2d\u9009\u62e9\u4f60\u7684Python\u9879\u76ee\u6587\u4ef6\u5939\u3002<\/li>\n<li><strong>\u538b\u7f29\u6587\u4ef6\u5939<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u6587\u4ef6\u5939\uff0c\u9009\u62e9\u201c\u53d1\u9001\u5230\u201d\u6216\u201c\u538b\u7f29\u201d\u9009\u9879\uff0c\u5c06\u6587\u4ef6\u5939\u538b\u7f29\u4e3a.zip\u6216.tar.gz\u683c\u5f0f\u3002<\/li>\n<li><strong>\u5206\u4eab\u538b\u7f29\u5305<\/strong>\uff1a\u5c06\u538b\u7f29\u5305\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u3001\u4e91\u5b58\u50a8\u670d\u52a1\uff08\u5982Google Drive\u3001Dropbox\u7b49\uff09\u5206\u4eab\u7ed9\u4ed6\u4eba\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u4e00\u6b21\u6027\u5206\u4eab\u6574\u4e2a\u9879\u76ee\u6587\u4ef6\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08\u5982.exe\u6587\u4ef6\uff09\uff0c\u4ee5\u4fbf\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528PyInstaller\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5PyInstaller<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>pip install pyinstaller<\/code>\u5b89\u88c5PyInstaller\u3002<\/li>\n<li><strong>\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u8fd0\u884c<code>pyinstaller --onefile &lt;your_script.py&gt;<\/code>\u547d\u4ee4\uff0c\u5176\u4e2d<code>&lt;your_script.py&gt;<\/code>\u662f\u4f60\u7684Python\u811a\u672c\u540d\u79f0\u3002PyInstaller\u5c06\u751f\u6210\u4e00\u4e2adist\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/li>\n<li><strong>\u8fd0\u884c\u53ef\u6267\u884c\u6587\u4ef6<\/strong>\uff1a\u5728dist\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53cc\u51fb\u8fd0\u884c\u5373\u53ef\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u4ee3\u7801\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5bfc\u51fa\u4e3aJupyter Notebook<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4f7f\u7528Jupyter Notebook\u7f16\u5199\u4ee3\u7801\uff0c\u53ef\u4ee5\u5c06\u4ee3\u7801\u5bfc\u51fa\u4e3a.ipynb\u6587\u4ef6\u683c\u5f0f\uff0c\u6216\u8005\u5bfc\u51fa\u4e3a\u5176\u4ed6\u683c\u5f0f\uff08\u5982HTML\u3001PDF\u7b49\uff09\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00Jupyter Notebook<\/strong>\uff1a\u542f\u52a8Jupyter Notebook\u670d\u52a1\u5668\uff0c\u5e76\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u4f60\u7684Notebook\u6587\u4ef6\u3002<\/li>\n<li><strong>\u5bfc\u51faNotebook<\/strong>\uff1a\u70b9\u51fb\u201c\u6587\u4ef6\u201d\u83dc\u5355\u4e2d\u7684\u201c\u4e0b\u8f7d\u4e3a\u201d\u9009\u9879\uff0c\u9009\u62e9\u9700\u8981\u7684\u6587\u4ef6\u683c\u5f0f\uff08\u5982Notebook (.ipynb)\u3001HTML\u3001PDF\u7b49\uff09\u3002<\/li>\n<li><strong>\u5206\u4eab\u5bfc\u51fa\u6587\u4ef6<\/strong>\uff1a\u5c06\u5bfc\u51fa\u7684\u6587\u4ef6\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u3001\u4e91\u5b58\u50a8\u670d\u52a1\u7b49\u65b9\u5f0f\u5206\u4eab\u7ed9\u4ed6\u4eba\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5206\u4eab\u5305\u542b\u4ee3\u7801\u3001\u6ce8\u91ca\u3001\u56fe\u8868\u7b49\u5185\u5bb9\u7684Notebook\u6587\u4ef6\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u81ea\u52a8\u5316\u5bfc\u51fa<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u590d\u6742\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u811a\u672c\u81ea\u52a8\u5316\u5bfc\u51fa\u4ee3\u7801\u548c\u76f8\u5173\u6587\u4ef6\u3002\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\uff0c\u4f7f\u7528shutil\u3001os\u7b49\u6a21\u5757\u5b9e\u73b0\u6587\u4ef6\u7684\u590d\u5236\u3001\u538b\u7f29\u7b49\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<p>import os<\/p>\n<p>def export_project(project_path, export_path):<\/p>\n<p>    # \u538b\u7f29\u9879\u76ee\u6587\u4ef6\u5939<\/p>\n<p>    shutil.make_archive(export_path, &#39;zip&#39;, project_path)<\/p>\n<p>    print(f&quot;Project exported to {export_path}.zip&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/h2>\n<p>project_path = &#39;\/path\/to\/your\/project&#39;<\/p>\n<p>export_path = &#39;\/path\/to\/export\/location\/project_backup&#39;<\/p>\n<p>export_project(project_path, export_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u811a\u672c\u5c06\u6307\u5b9a\u7684\u9879\u76ee\u6587\u4ef6\u5939\u538b\u7f29\u4e3a.zip\u6587\u4ef6\uff0c\u5e76\u4fdd\u5b58\u5230\u6307\u5b9a\u4f4d\u7f6e\u3002\u901a\u8fc7\u81ea\u52a8\u5316\u811a\u672c\uff0c\u53ef\u4ee5\u7b80\u5316\u5bfc\u51fa\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u5bfc\u51fa\u4ee3\u7801\u7247\u6bb5<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u53ea\u9700\u8981\u5206\u4eab\u4ee3\u7801\u7247\u6bb5\uff0c\u800c\u4e0d\u662f\u6574\u4e2a\u9879\u76ee\u3002\u53ef\u4ee5\u4f7f\u7528\u5728\u7ebf\u4ee3\u7801\u5206\u4eab\u5e73\u53f0\uff08\u5982Gist\u3001Pastebin\u7b49\uff09\u5bfc\u51fa\u548c\u5206\u4eab\u4ee3\u7801\u7247\u6bb5\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528GitHub Gist\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00GitHub Gist\u7f51\u7ad9<\/strong>\uff1a\u8bbf\u95eegist.github.com\u3002<\/li>\n<li><strong>\u521b\u5efa\u65b0\u7684Gist<\/strong>\uff1a\u70b9\u51fb\u201c+\u201d\u6309\u94ae\u521b\u5efa\u65b0\u7684Gist\u3002<\/li>\n<li><strong>\u7c98\u8d34\u4ee3\u7801\u7247\u6bb5<\/strong>\uff1a\u5c06\u4ee3\u7801\u7247\u6bb5\u7c98\u8d34\u5230\u6587\u672c\u6846\u4e2d\uff0c\u586b\u5199\u63cf\u8ff0\u4fe1\u606f\uff0c\u5e76\u9009\u62e9\u516c\u5f00\u6216\u79c1\u6709\u3002<\/li>\n<li><strong>\u4fdd\u5b58\u5e76\u5206\u4eab<\/strong>\uff1a\u70b9\u51fb\u201cCreate secret gist\u201d\u6216\u201cCreate public gist\u201d\u6309\u94ae\u4fdd\u5b58Gist\uff0c\u5e76\u5c06\u751f\u6210\u7684\u94fe\u63a5\u5206\u4eab\u7ed9\u4ed6\u4eba\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5feb\u901f\u5206\u4eab\u4ee3\u7801\u7247\u6bb5\u7684\u60c5\u51b5\uff0c\u5c24\u5176\u662f\u5728\u7ebf\u8ba8\u8bba\u6216\u95ee\u7b54\u65f6\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u5bfc\u51fa\u4e3a\u6587\u6863<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u4ee3\u7801\u5bfc\u51fa\u4e3a\u6587\u6863\u683c\u5f0f\uff08\u5982Markdown\u3001HTML\u3001PDF\u7b49\uff09\uff0c\u4ee5\u4fbf\u4e8e\u64b0\u5199\u6280\u672f\u6587\u6863\u6216\u535a\u5ba2\u6587\u7ae0\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Pandoc\u5c06Markdown\u6587\u6863\u5bfc\u51fa\u4e3aPDF\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7f16\u5199Markdown\u6587\u6863<\/strong>\uff1a\u5728Markdown\u6587\u4ef6\u4e2d\u7f16\u5199\u4ee3\u7801\u548c\u76f8\u5173\u8bf4\u660e\uff0c\u4f7f\u7528\u4ee3\u7801\u5757\u683c\u5f0f\u5316\u4ee3\u7801\u3002<\/li>\n<li><strong>\u5b89\u88c5Pandoc<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>sudo apt-get install pandoc<\/code>\uff08Linux\uff09\u6216<code>brew install pandoc<\/code>\uff08macOS\uff09\u5b89\u88c5Pandoc\u3002<\/li>\n<li><strong>\u5bfc\u51fa\u4e3aPDF<\/strong>\uff1a\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c<code>pandoc &lt;your_markdown.md&gt; -o &lt;output.pdf&gt;<\/code>\u547d\u4ee4\uff0c\u5176\u4e2d<code>&lt;your_markdown.md&gt;<\/code>\u662fMarkdown\u6587\u4ef6\u540d\u79f0\uff0c<code>&lt;output.pdf&gt;<\/code>\u662f\u8f93\u51fa\u7684PDF\u6587\u4ef6\u540d\u79f0\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5c06\u4ee3\u7801\u548c\u6587\u6863\u6574\u5408\u5728\u4e00\u8d77\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u4f7f\u7528Docker\u5bb9\u5668\u5316\u5bfc\u51fa<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u590d\u6742\u9879\u76ee\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528Docker\u5c06\u6574\u4e2a\u9879\u76ee\u5bb9\u5668\u5316\uff0c\u4ee5\u4fbf\u4e8e\u90e8\u7f72\u548c\u5206\u4eab\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Docker\u5bb9\u5668\u5316\u5bfc\u51fa\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7f16\u5199Dockerfile<\/strong>\uff1a\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2aDockerfile\uff0c\u5b9a\u4e49\u9879\u76ee\u7684\u4f9d\u8d56\u548c\u8fd0\u884c\u73af\u5883\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-Dockerfile\">FROM python:3.8-slim<\/p>\n<p>WORKDIR \/app<\/p>\n<p>COPY . \/app<\/p>\n<p>RUN pip install -r requirements.txt<\/p>\n<p>CMD [&quot;python&quot;, &quot;your_script.py&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6784\u5efaDocker\u955c\u50cf<\/strong>\uff1a\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c<code>docker build -t your_project .<\/code>\u547d\u4ee4\uff0c\u6784\u5efaDocker\u955c\u50cf\u3002<\/li>\n<li><strong>\u8fd0\u884cDocker\u5bb9\u5668<\/strong>\uff1a\u4f7f\u7528<code>docker run -it --rm your_project<\/code>\u547d\u4ee4\u8fd0\u884cDocker\u5bb9\u5668\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7Docker\u5bb9\u5668\u5316\uff0c\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u5728\u4efb\u4f55\u73af\u5883\u4e0b\u90fd\u80fd\u4e00\u81f4\u8fd0\u884c\uff0c\u9002\u7528\u4e8e\u9700\u8981\u8de8\u5e73\u53f0\u90e8\u7f72\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u4e5d\u3001\u5bfc\u51fa\u4e3a\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u9879\u76ee\u7684\u865a\u62df\u73af\u5883\u4e00\u540c\u5bfc\u51fa\uff0c\u4ee5\u4fbf\u4e8e\u4ed6\u4eba\u5728\u76f8\u540c\u7684\u73af\u5883\u4e2d\u8fd0\u884c\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u5bfc\u51fa\u865a\u62df\u73af\u5883\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u8fd0\u884c<code>python -m venv venv<\/code>\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/li>\n<li><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728Windows\u4e0a\u8fd0\u884c<code>venv\\Scripts\\activate<\/code>\uff0c\u5728macOS\u6216Linux\u4e0a\u8fd0\u884c<code>source venv\/bin\/activate<\/code>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/li>\n<li><strong>\u5b89\u88c5\u4f9d\u8d56<\/strong>\uff1a\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fd0\u884c<code>pip install -r requirements.txt<\/code>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56\u3002<\/li>\n<li><strong>\u5bfc\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5c06\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939\uff08\u5982venv\uff09\u548c\u9879\u76ee\u6587\u4ef6\u4e00\u8d77\u6253\u5305\u4e3a\u538b\u7f29\u5305\uff0c\u6216\u8005\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u7ba1\u7406\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u786e\u4fdd\u4f9d\u8d56\u4e00\u81f4\u6027\u7684\u9879\u76ee\u3002<\/p>\n<\/p>\n<p><p>\u5341\u3001\u4f7f\u7528<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\u5de5\u5177\u81ea\u52a8\u5bfc\u51fa<\/p>\n<\/p>\n<p><p>\u5728\u6301\u7eed\u96c6\u6210\/\u6301\u7eed\u90e8\u7f72\uff08CI\/CD\uff09\u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528CI\/CD\u5de5\u5177\uff08\u5982Jenkins\u3001GitHub Actions\u3001GitLab CI\u7b49\uff09\u81ea\u52a8\u5bfc\u51fa\u548c\u90e8\u7f72\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528GitHub Actions\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efaGitHub Actions\u5de5\u4f5c\u6d41\u6587\u4ef6<\/strong>\uff1a\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa<code>.github\/workflows\/deploy.yml<\/code>\u6587\u4ef6\uff0c\u5b9a\u4e49CI\/CD\u5de5\u4f5c\u6d41\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-yaml\">name: Deploy<\/p>\n<p>on:<\/p>\n<p>  push:<\/p>\n<p>    branches:<\/p>\n<p>      - m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n<\/p>\n<p>jobs:<\/p>\n<p>  build:<\/p>\n<p>    runs-on: ubuntu-latest<\/p>\n<p>    steps:<\/p>\n<p>      - name: Checkout code<\/p>\n<p>        uses: actions\/checkout@v2<\/p>\n<p>      - name: Set up Python<\/p>\n<p>        uses: actions\/setup-python@v2<\/p>\n<p>        with:<\/p>\n<p>          python-version: 3.8<\/p>\n<p>      - name: Install dependencies<\/p>\n<p>        run: pip install -r requirements.txt<\/p>\n<p>      - name: Run tests<\/p>\n<p>        run: pytest<\/p>\n<p>      - name: Deploy<\/p>\n<p>        run: echo &quot;Deploying code...&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u63a8\u9001\u4ee3\u7801\u5230GitHub<\/strong>\uff1a\u5c06\u4ee3\u7801\u63a8\u9001\u5230GitHub\u4ed3\u5e93\uff0cGitHub Actions\u5c06\u81ea\u52a8\u6267\u884c\u5de5\u4f5c\u6d41\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7CI\/CD\u5de5\u5177\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u7684\u4ee3\u7801\u5bfc\u51fa\u548c\u90e8\u7f72\uff0c\u63d0\u9ad8\u6548\u7387\u548c\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0a\u4ecb\u7ecd\u4e86\u591a\u79cd\u5bfc\u51faPython\u4ee3\u7801\u7684\u65b9\u6cd5\uff0c\u5305\u62ec<strong>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u4fdd\u5b58\u6587\u4ef6\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3001\u5bfc\u51fa\u4e3a\u538b\u7f29\u5305\u3001\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5bfc\u51fa\u4e3aJupyter Notebook\u3001\u81ea\u52a8\u5316\u5bfc\u51fa\u3001\u5bfc\u51fa\u4ee3\u7801\u7247\u6bb5\u3001\u5bfc\u51fa\u4e3a\u6587\u6863\u3001\u4f7f\u7528Docker\u5bb9\u5668\u5316\u5bfc\u51fa\u3001\u5bfc\u51fa\u4e3a\u865a\u62df\u73af\u5883\u3001\u4f7f\u7528CI\/CD\u5de5\u5177\u81ea\u52a8\u5bfc\u51fa<\/strong>\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u548c\u5206\u4eabPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982PyInstaller\u6216cx_Freeze\u5c06Python\u4ee3\u7801\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u4e9b\u5de5\u5177\u4f1a\u5c06\u60a8\u7684\u811a\u672c\u548c\u6240\u6709\u4f9d\u8d56\u9879\u6253\u5305\u5728\u4e00\u8d77\uff0c\u65b9\u4fbf\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u3002\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165\u76f8\u5e94\u7684\u547d\u4ee4\u5373\u53ef\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p><strong>Python\u4ee3\u7801\u5bfc\u51fa\u540e\u5982\u4f55\u5206\u4eab\u7ed9\u4ed6\u4eba\uff1f<\/strong><br \/>\u5bfc\u51fa\u7684Python\u4ee3\u7801\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5206\u4eab\uff0c\u5982\u901a\u8fc7\u7535\u5b50\u90ae\u4ef6\u53d1\u9001\u3001\u4e0a\u4f20\u5230\u4e91\u5b58\u50a8\u670d\u52a1\uff08\u5982Google Drive\u6216Dropbox\uff09\u6216\u8005\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982GitHub\uff09\u3002\u786e\u4fdd\u63a5\u6536\u8005\u6709\u5fc5\u8981\u7684\u8fd0\u884c\u73af\u5883\u6216\u63d0\u4f9b\u76f8\u5e94\u7684\u8bf4\u660e\uff0c\u4ee5\u4fbf\u4ed6\u4eec\u80fd\u987a\u5229\u8fd0\u884c\u60a8\u7684\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06Python\u4ee3\u7801\u5bfc\u51fa\u4e3a\u5176\u4ed6\u683c\u5f0f\uff0c\u5982PDF\u6216HTML\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528\u5e93\u5982<code>nbconvert<\/code>\uff08\u5bf9\u4e8eJupyter Notebook\uff09\u5c06\u4ee3\u7801\u5bfc\u51fa\u4e3aPDF\u6216HTML\u683c\u5f0f\u3002\u5bf9\u4e8e\u666e\u901aPython\u811a\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6587\u6863\u751f\u6210\u5de5\u5177\u5982Sphinx\u6216Markdown\uff0c\u5c06\u4ee3\u7801\u548c\u6ce8\u91ca\u683c\u5f0f\u5316\u6210\u6613\u4e8e\u9605\u8bfb\u7684\u6587\u6863\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u9700\u8981\u5206\u4eab\u4ee3\u7801\u548c\u5176\u8bf4\u660e\u7684\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7f16\u5199\u5b8cPython\u4ee3\u7801\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5bfc\u51fa\u4ee3\u7801\u6587\u4ef6\uff0c\u4ee5\u4fbf\u8fdb\u884c\u5206\u4eab\u3001\u5907\u4efd\u6216\u8005\u90e8\u7f72\u3002\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u6587\u672c\u7f16\u8f91 [&hellip;]","protected":false},"author":3,"featured_media":1180084,"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\/1180076"}],"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=1180076"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1180076\/revisions"}],"predecessor-version":[{"id":1180087,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1180076\/revisions\/1180087"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1180084"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1180076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1180076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1180076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}