{"id":967931,"date":"2024-12-27T05:02:00","date_gmt":"2024-12-26T21:02:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/967931.html"},"modified":"2024-12-27T05:02:03","modified_gmt":"2024-12-26T21:02:03","slug":"python3-5-%e5%a6%82%e4%bd%95%e6%89%93%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/967931.html","title":{"rendered":"python3.5 \u5982\u4f55\u6253\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24182948\/60f1b274-cec9-4801-8c90-16a073215fc4.webp\" alt=\"python3.5 \u5982\u4f55\u6253\u5305\" \/><\/p>\n<p><p> <strong>Python 3.5\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u6253\u5305\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528PyInstaller\u3001cx_Freeze\u4ee5\u53casetuptools\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002<\/strong>\u5176\u4e2d\uff0cPyInstaller\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5de5\u5177\uff0c\u56e0\u4e3a\u5b83\u652f\u6301\u591a\u5e73\u53f0\uff0c\u80fd\u591f\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528PyInstaller\u7684\u4e00\u4e2a\u663e\u8457\u4f18\u52bf\u662f\u7b80\u5316\u4e86\u6253\u5305\u6d41\u7a0b\uff0c\u5e76\u4e14\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e0d\u4f9d\u8d56\u4e8e\u76ee\u6807\u7cfb\u7edf\u4e0a\u662f\u5426\u5b89\u88c5\u4e86Python\u89e3\u91ca\u5668\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u6253\u5305\u65b9\u6cd5\uff0c\u5e76\u5206\u4eab\u4e00\u4e9b\u5b9e\u7528\u6280\u5de7\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001PYINSTALLER<\/p>\n<\/p>\n<p><p>PyInstaller\u662f\u4e00\u4e2a\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u652f\u6301Windows\u3001macOS\u548cLinux\u5e73\u53f0\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5PyInstaller<\/strong><\/li>\n<\/ol>\n<p><p>\u8981\u4f7f\u7528PyInstaller\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u5b83\u3002\u53ef\u4ee5\u901a\u8fc7pip\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u57fa\u672c\u4f7f\u7528<\/strong><\/li>\n<\/ol>\n<p><p>PyInstaller\u7684\u57fa\u672c\u7528\u6cd5\u975e\u5e38\u7b80\u5355\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a<code>m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/code>\u7684Python\u811a\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller main.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a<code>dist<\/code>\u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u4e00\u4e2a\u540d\u4e3a<code>main<\/code>\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728Windows\u4e0a\uff0c\u8fd9\u4e2a\u6587\u4ef6\u662f<code>main.exe<\/code>\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u9ad8\u7ea7\u9009\u9879<\/strong><\/li>\n<\/ol>\n<p><p>PyInstaller\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u9009\u9879\uff0c\u6bd4\u5982\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile main.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u6307\u5b9a\u56fe\u6807\u6587\u4ef6\uff0c\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --windowed --icon=app.ico main.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528PyInstaller\u65f6\uff0c\u6709\u4e9bPython\u5e93\u53ef\u80fd\u9700\u8981\u989d\u5916\u7684hooks\u6216\u8bbe\u7f6e\uff0c\u6bd4\u5982PyQt5\u3001Pandas\u7b49\u3002\u53ef\u4ee5\u53c2\u8003PyInstaller\u7684\u5b98\u65b9\u6587\u6863\u6216\u793e\u533a\u8d44\u6e90\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001CX_FREEZE<\/p>\n<\/p>\n<p><p>cx_Freeze\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u7279\u522b\u9002\u5408\u7528\u4e8e\u9700\u8981\u8de8\u5e73\u53f0\u90e8\u7f72\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5cx_Freeze<\/strong><\/li>\n<\/ol>\n<p><p>\u4e0ePyInstaller\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5cx_Freeze\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install cx_Freeze<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u521b\u5efasetup\u811a\u672c<\/strong><\/li>\n<\/ol>\n<p><p>cx_Freeze\u9700\u8981\u4e00\u4e2asetup\u811a\u672c\u6765\u6307\u5b9a\u6253\u5305\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from cx_Freeze import setup, Executable<\/p>\n<p>setup(<\/p>\n<p>    name=&quot;MyApp&quot;,<\/p>\n<p>    version=&quot;0.1&quot;,<\/p>\n<p>    description=&quot;My application&quot;,<\/p>\n<p>    executables=[Executable(&quot;main.py&quot;)]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py build<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u9ad8\u7ea7\u914d\u7f6e<\/strong><\/li>\n<\/ol>\n<p><p>cx_Freeze\u652f\u6301\u8bb8\u591a\u9ad8\u7ea7\u914d\u7f6e\u9009\u9879\uff0c\u6bd4\u5982\u6dfb\u52a0\u989d\u5916\u7684\u6587\u4ef6\u3001\u6307\u5b9a\u4f9d\u8d56\u5e93\u7b49\u3002\u53ef\u4ee5\u5728<code>setup<\/code>\u51fd\u6570\u4e2d\u8bbe\u7f6e<code>options<\/code>\u53c2\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/li>\n<\/ol>\n<p><p>cx_Freeze\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u7684\u8868\u73b0\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u52a8\u6001\u94fe\u63a5\u5e93\u65f6\u3002\u5efa\u8bae\u5728\u6240\u6709\u76ee\u6807\u5e73\u53f0\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001SETUPTOOLS<\/p>\n<\/p>\n<p><p>setuptools\u901a\u5e38\u7528\u4e8e\u53d1\u5e03\u548c\u5206\u53d1Python\u5e93\uff0c\u4f46\u4e5f\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u7b80\u5355\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efasetup\u811a\u672c<\/strong><\/li>\n<\/ol>\n<p><p>\u4e0ecx_Freeze\u7c7b\u4f3c\uff0csetuptools\u4e5f\u9700\u8981\u4e00\u4e2asetup\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from setuptools import setup<\/p>\n<p>setup(<\/p>\n<p>    name=&quot;MyApp&quot;,<\/p>\n<p>    version=&quot;0.1&quot;,<\/p>\n<p>    py_modules=[&quot;main&quot;],<\/p>\n<p>    entry_points={<\/p>\n<p>        &#39;console_scripts&#39;: [<\/p>\n<p>            &#39;myapp = main:main&#39;,<\/p>\n<p>        ],<\/p>\n<p>    },<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py bdist_egg<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4f18\u70b9\u4e0e\u9650\u5236<\/strong><\/li>\n<\/ol>\n<p><p>setuptools\u7684\u4e00\u4e2a\u4f18\u70b9\u662f\u4e0ePython\u751f\u6001\u7cfb\u7edf\u7684\u6df1\u5ea6\u96c6\u6210\uff0c\u9002\u5408\u7528\u4e8e\u5206\u53d1Python\u5e93\u3002\u4f46\u5bf9\u4e8e\u590d\u6742\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u80fd\u9700\u8981\u7ed3\u5408\u5176\u4ed6\u5de5\u5177\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5176\u4ed6\u6253\u5305\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u5e38\u7528\u5de5\u5177\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u5de5\u5177\u548c\u65b9\u6cd5\u53ef\u4ee5\u7528\u4e8ePython 3.5\u7684\u6253\u5305\uff0c\u6bd4\u5982Py2exe\u3001Nuitka\u7b49\u3002\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u9700\u8981\u6839\u636e\u9879\u76ee\u7684\u9700\u6c42\u3001\u76ee\u6807\u5e73\u53f0\u4ee5\u53ca\u6253\u5305\u540e\u7684\u6027\u80fd\u8868\u73b0\u6765\u51b3\u5b9a\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>Py2exe<\/strong><\/li>\n<\/ol>\n<p><p>Py2exe\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8eWindows\u5e73\u53f0\u7684\u6253\u5305\u5de5\u5177\uff0c\u9002\u5408\u90a3\u4e9b\u4ec5\u9700\u5728Windows\u4e0a\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>Nuitka<\/strong><\/li>\n<\/ol>\n<p><p>Nuitka\u4e0d\u4ec5\u662f\u4e00\u4e2a\u6253\u5305\u5de5\u5177\uff0c\u8fd8\u662f\u4e00\u4e2aPython\u5230C\u7684\u7f16\u8bd1\u5668\uff0c\u53ef\u4ee5\u751f\u6210\u9ad8\u6548\u7684\u673a\u5668\u7801\uff0c\u4ece\u800c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728\u9009\u62e9Python\u6253\u5305\u5de5\u5177\u65f6\uff0c\u9700\u8981\u7efc\u5408\u8003\u8651\u5e94\u7528\u7a0b\u5e8f\u7684\u590d\u6742\u5ea6\u3001\u76ee\u6807\u5e73\u53f0\u3001\u5f00\u53d1\u5468\u671f\u4ee5\u53ca\u6027\u80fd\u9700\u6c42\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u5de5\u5177\uff0c\u52a1\u5fc5\u4ed4\u7ec6\u9605\u8bfb\u76f8\u5173\u6587\u6863\uff0c\u5e76\u5728\u591a\u79cd\u73af\u5883\u4e2d\u8fdb\u884c\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u80fd\u591f\u6b63\u5e38\u8fd0\u884c\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\uff0c\u53ef\u4ee5\u5927\u5927\u7b80\u5316Python\u5e94\u7528\u7a0b\u5e8f\u7684\u90e8\u7f72\u548c\u5206\u53d1\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python 3.5\u4e2d\u521b\u5efa\u4e00\u4e2a\u53ef\u5206\u53d1\u7684\u5305\uff1f<\/strong><br \/>\u5728Python 3.5\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>setuptools<\/code>\u5e93\u6765\u521b\u5efa\u53ef\u5206\u53d1\u7684\u5305\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86<code>setuptools<\/code>\u548c<code>wheel<\/code>\u3002\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>setup.py<\/code>\u6587\u4ef6\uff0c\u586b\u5199\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u6bd4\u5982\u5305\u540d\u3001\u7248\u672c\u3001\u4f5c\u8005\u3001\u63cf\u8ff0\u7b49\u3002\u7136\u540e\uff0c\u901a\u8fc7\u8fd0\u884c\u547d\u4ee4<code>python setup.py sdist bdist_wheel<\/code>\u6765\u751f\u6210\u6e90\u4ee3\u7801\u5206\u53d1\u5305\u548cwheel\u5305\u3002<\/p>\n<p><strong>\u6253\u5305Python 3.5\u9879\u76ee\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u6253\u5305Python\u9879\u76ee\u65f6\uff0c\u901a\u5e38\u9700\u8981\u5305\u542b<code>setup.py<\/code>\u3001<code>requirements.txt<\/code>\uff08\u5982\u679c\u6709\u4f9d\u8d56\uff09\u3001<code>README.md<\/code>\uff08\u9879\u76ee\u8bf4\u660e\u6587\u4ef6\uff09\u548c\u4f60\u7684\u6e90\u4ee3\u7801\u6587\u4ef6\u5939\u3002\u786e\u4fdd\u5c06\u6240\u6709\u9700\u8981\u7684\u6a21\u5757\u548c\u8d44\u6e90\u6587\u4ef6\u4e5f\u5305\u542b\u5728\u5185\uff0c\u4ee5\u4fbf\u7528\u6237\u80fd\u591f\u987a\u5229\u5b89\u88c5\u548c\u4f7f\u7528\u4f60\u7684\u5305\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python 3.5\u4e2d\u5b89\u88c5\u6211\u6253\u5305\u7684\u5305\uff1f<\/strong><br \/>\u8981\u5b89\u88c5\u81ea\u5df1\u6253\u5305\u7684Python 3.5\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u547d\u4ee4\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5728\u5305\u7684\u6839\u76ee\u5f55\u4e0b\uff0c\u7136\u540e\u8fd0\u884c<code>pip install .<\/code>\u3002\u8fd9\u6761\u547d\u4ee4\u4f1a\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u7684<code>setup.py<\/code>\u6587\u4ef6\u5e76\u5b89\u88c5\u8be5\u5305\u3002\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fwheel\u683c\u5f0f\u7684\u5305\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>pip install package_name.whl<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python 3.5\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u6253\u5305\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528PyInstaller\u3001cx_Freeze\u4ee5\u53ca [&hellip;]","protected":false},"author":3,"featured_media":967936,"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\/967931"}],"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=967931"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/967931\/revisions"}],"predecessor-version":[{"id":967937,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/967931\/revisions\/967937"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/967936"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=967931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=967931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=967931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}