{"id":5005,"date":"2022-03-23T22:42:00","date_gmt":"2022-03-23T14:42:00","guid":{"rendered":"https:\/\/www.yumefx.com\/?p=5005"},"modified":"2022-03-24T11:43:10","modified_gmt":"2022-03-24T03:43:10","slug":"py%e8%84%9a%e6%9c%ac%e6%89%93%e5%8c%85%e6%88%90pyd%e5%ba%93","status":"publish","type":"post","link":"https:\/\/www.yumefx.com\/?p=5005","title":{"rendered":"py\u811a\u672c\u6253\u5305\u6210pyd\u5e93"},"content":{"rendered":"\n<h1 style=\"text-align: center;\">\u524d\u8a00<\/h1>\n<p>\u4ee5\u524d\u66f4\u65b0\u8fc7\u4e00\u7bc7<a href=\"https:\/\/www.yumefx.com\/?p=1133\">pyinstaller\u2014py\u811a\u672c\u6253\u5305\u6210exe<\/a>\uff0c\u8bf4\u7684\u662f\u5c06Python\u811a\u672c\u6253\u5305\u6210exe\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6765\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u540c\u65f6\u4e5f\u80fd\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u4fdd\u62a4\u4ee3\u7801\u4e0d\u88ab\u6cc4\u6f0f\u3002<\/p>\n<p>\u4f46\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u5bf9\u4e8e\u591a\u4eba\u534f\u4f5c\u7684\u5927\u578b\u9879\u76ee\uff0c\u6216\u8005\u662f\u57fa\u4e8e\u652f\u6301Python\u7684\u5546\u4e1a\u8f6f\u4ef6\u7684\u4e8c\u6b21\u5f00\u53d1\u7b49\uff0c\u5982\u679c\u5c06py\u811a\u672c\u6253\u5305\u6210exe\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4e0d\u4ec5\u4e0d\u65b9\u4fbf\u8c03\u7528\uff0c\u5e76\u4e14\u8fd0\u884c\u6548\u7387\u4e5f\u6bd4\u8f83\u5dee\uff0c\u6b64\u65f6\u5f80\u5f80\u4f1a\u628apy\u811a\u672c\u7f16\u8bd1\u6210pyd\u5e93\uff0c\u518d\u5bfc\u5165\u8c03\u7528\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4eca\u5929\u5c31\u6765\u4ecb\u7ecd\u4e00\u4e0bpyd\u7684\u7f16\u8bd1\u65b9\u6cd5\u4ee5\u53ca\u4e00\u4e9b\u95ee\u9898\u3002<\/p>\n<h1>&nbsp;<\/h1>\n<h1 style=\"text-align: center;\">\u7f16\u8bd1pyd\u524d\u7684\u51c6\u5907<\/h1>\n<p>\u6240\u8c13pyd\u6587\u4ef6\uff0c\u5c31\u662fD\u8bed\u8a00(C\/C++\u7efc\u5408\u8fdb\u5316\u7248\u672c)\u7f16\u5199\u7684\u4e00\u79cddll \u6587\u4ef6\uff0c\u76f8\u6bd4\u8d77\u5bb9\u6613\u88ab\u53cd\u7f16\u8bd1\u7684pyc\u6587\u4ef6\uff0cpyd\u6587\u4ef6\u76ee\u524d\u8fd8\u6ca1\u6709\u529e\u6cd5\u8fdb\u884c\u53cd\u7f16\u8bd1\uff0c\u53ea\u80fd\u88ab\u53cd\u6c47\u7f16\uff0c\u56e0\u6b64\u6709\u5f88\u9ad8\u7684\u5b89\u5168\u6027\uff0c\u5e76\u4e14\u8fd0\u884c\u6548\u7387\u4e5f\u6bd4\u8f83\u9ad8\u3002<\/p>\n<p>\u8981\u60f3\u7f16\u8bd1pyd\uff0c\u9996\u5148\u8981\u901a\u8fc7pip\u5b89\u88c5Cython\u548csetuptools\u5e93\u3002<\/p>\n\n\n\n<pre><span>pip install cython<\/span>\n<span>pip install setuptools<\/span>\n<\/pre>\n\n\n\n<p>\u5982\u679cPython\u4e2d\u8fdepip\u4e5f\u6ca1\u6709\uff0c\u90a3\u4e48\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b89\u88c5pip\u3002<\/p>\n<p>\u5148\u5c06<a href=\"https:\/\/bootstrap.pypa.io\/get-pip.py\">https:\/\/bootstrap.pypa.io\/get-pip.py<\/a>\u4e0b\u8f7d\u5230\u672c\u5730\uff0c\u7136\u540e\u7528Python\u8fd0\u884c\uff0c\u3002<\/p>\n\n\n\n<pre><span>python get-pip.py<\/span>\n<\/pre>\n\n\n\n<p>\u88c5\u597dpip\u540e\uff0csetuptools\u4e5f\u4f1a\u81ea\u52a8\u5b89\u88c5\uff0c\u7136\u540e\u53ea\u9700\u8981\u4f7f\u7528pip\u5b89\u88c5Cython\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u9664\u4e86Cython\u548csetuptools\u8fd9\u4e24\u4e2apython\u5e93\u4ee5\u5916\uff0c\u5728windows\u4e0a\u7f16\u8bd1pyd\uff0c\u8fd8\u9700\u8981\u5b89\u88c5Microsoft Visual C++ 14.0\uff0c\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u5c31\u662f\u5b89\u88c5Visual Studio 2015\u4ee5\u4e0a\u7248\u672c\uff0c\u53ef\u4ee5\u76f4\u63a5\u53bb<a href=\"https:\/\/visualstudio.microsoft.com\/zh-hans\/\">\u5b98\u7f51<\/a>\u4e0b\u8f7d\uff0c\u6216\u8005\u7528\u6211\u63d0\u4f9b\u7684<a href=\"https:\/\/www.yumefx.com\/files\/vs_enterprise__365253659.1556938083.exe\">VS2019\u5728\u7ebf\u5b89\u88c5\u7a0b\u5e8f<\/a>\u3002<\/p>\n<p>\u5728\u5b89\u88c5\u65f6\u6ce8\u610f\u52fe\u9009\u4e0a\u4ee5\u4e0b\u51e0\u4e2a\u7ec4\u4ef6\uff0c\u7b49\u5f85\u5b89\u88c5\u5b8c\u6bd5\u5373\u53ef\u3002<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-5008 aligncenter\" src=\"https:\/\/www.yumefx.com\/wp-content\/uploads\/2022\/03\/PythonPyd_01.jpg\" alt=\"\" width=\"1288\" height=\"717\" srcset=\"https:\/\/www.yumefx.com\/wp-content\/uploads\/2022\/03\/PythonPyd_01.jpg 1288w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2022\/03\/PythonPyd_01-300x167.jpg 300w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2022\/03\/PythonPyd_01-1024x570.jpg 1024w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2022\/03\/PythonPyd_01-768x428.jpg 768w\" sizes=\"(max-width: 1288px) 100vw, 1288px\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u8fd9\u79cd\u65b9\u5f0f\u53ea\u80fd\u5728\u7ebf\u5b89\u88c5\uff0c\u5e76\u4e14\u4f1a\u5360\u7528\u8f83\u591a\u5b58\u50a8\u7a7a\u95f4\uff0c\u5982\u679c\u4e0d\u60f3\u5b89\u88c5\u6574\u4e2aVisual Studio\u5f00\u53d1\u73af\u5883\uff0c\u53ea\u60f3\u5feb\u901f\u90e8\u7f72\u597dpyd\u7684\u7f16\u8bd1\u6240\u9700\u73af\u5883\uff0c\u53ef\u4ee5\u5230<a href=\"https:\/\/pan.baidu.com\/s\/1TIuK1ufDeaHuZ-GJB_GZSg?pwd=yume\">\u767e\u5ea6\u7f51\u76d8<\/a>\u4e0b\u8f7d\u5b89\u88c5Microsoft Visual C++ Build Tools\u79bb\u7ebf\u5b89\u88c5\u5305\uff0c\u5c06\u4e0b\u8f7d\u4e0b\u6765\u7684ISO\u955c\u50cf\u88c5\u8f7d\u5230\u865a\u62df\u5149\u9a71\u4e2d\u76f4\u63a5\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<h1>&nbsp;<\/h1>\n<h1 style=\"text-align: center;\">pyd\u7684\u7f16\u8bd1<\/h1>\n<p>\u51c6\u5907\u597d\u7f16\u8bd1\u73af\u5883\u540e\u5c31\u53ef\u4ee5\u8fdb\u884c\u7f16\u8bd1\u4e86\uff0c\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u7f16\u8bd1\u7684py\u811a\u672c\u4f8b\u5982setup.py\uff0c\u5185\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<pre><span>import os<\/span>\n<span><\/span>\n<span>import setuptools <\/span>\n<span>from distutils.core import setup<\/span>\n<span>from Cython.Build import cythonize<\/span>\n<span>from distutils.extension import Extension<\/span>\n<span><\/span>\n<span>extensions = []<\/span>\n<span>if os.path.exists('.\/test.py'):<\/span>\n<span>    extensions.append(Extension('test',['test.py']))<\/span>\n<span>    <\/span>\n<span>setup(ext_modules = cythonize(extensions, compiler_directives={'language_level': 2}),)<\/span>\n<\/pre>\n\n\n\n<p>\u5176\u4e2d\u7684test.py\u5c31\u662f\u8981\u7f16\u8bd1\u7684python\u811a\u672c\uff0c\u800clanguage_level\u53c2\u6570\u4e3a2\u4ee3\u8868python\u7248\u672c\u4e3a2.X\uff0c\u5982\u679c\u8981\u6253\u5305python3.X\u7248\u672c\u65f6\uff0c\u8fd9\u4e2a\u53c2\u6570\u5e94\u8be5\u4e3a3\u3002<\/p>\n<p>\u6700\u540e\u518d\u7528python\u8fd0\u884c\u8fd9\u4e2asetup.py\u5e76\u52a0\u4e0a\u4e24\u4e2a\u53c2\u6570\uff0c\u5373\u53ef\u5f00\u59cb\u7f16\u8bd1pyd\u3002<\/p>\n\n\n\n<pre><span>python setup.py build_ext --inplace<\/span>\n<\/pre>\n\n\n\n<p>\u5bf9\u4e8epython2.X\u7248\u672c\uff0c\u7f16\u8bd1\u597d\u7684pyd\u6587\u4ef6\u540d\u79f0\u548cpy\u6587\u4ef6\u76f8\u540c\uff0c\u4f8b\u5982test.py\u7f16\u8bd1\u5b8c\u540e\u4e3atest.pyd\uff1b\u800c\u5bf9\u4e8epython3.X\u7248\u672c\uff0c\u7f16\u8bd1\u597d\u7684pyd\u6587\u4ef6\u4f1a\u5e26\u6709\u540e\u7f00\uff0c\u4f8b\u5982test.py\u752864\u4f4dwindows\u7cfb\u7edf\u4e0a\u7684python3.7\u7f16\u8bd1\u540e\u662ftest.cp37-win_amd64.pyd\uff0c\u8fd9\u4e2apyd\u540d\u79f0\u4e0d\u8981\u4fee\u6539\uff0cpython\u5728import\u5e93\u65f6\u4f1a\u81ea\u52a8\u8bc6\u522b\u3002<\/p>\n<p>\u53e6\u5916\u5728\u90e8\u7f72\u5b8c\u73af\u5883\u540e\u7b2c\u4e00\u6b21\u8fd0\u884c\u7f16\u8bd1\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u7684\u62a5\u9519\u3002<\/p>\n\n\n\n<pre><span>\u6b63\u5728\u751f\u6210<\/span>\n<span>\u5df2\u5b8c\u6210\u4ee3\u7801\u7684\u751f\u6210<\/span>\n<span>LINK\uff1afata1 error LNK1158:\u65e0\u6cd5\u8fd0\u884c\u201crc.exe\u201d<\/span>\n<span>error\uff1acommand\u2018C:\\\\Program Files (x86)\\\\Microsoft Visual Studio 14.0\\\\VC\\\\BIN\\\\x86_amd64\\\\link.exe\u2019  failed with exit status 1158<\/span>\n<\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u95ee\u9898\u4e5f\u597d\u89e3\u51b3\uff0c\u5c06<code>C:\\Program Files (x86)\\Windows Kits\\8.1\\bin\\x86<\/code>\u6587\u4ef6\u5939\u4e2d\u7684<code>rc.exe<\/code>\u548c<code>rcdll.dll<\/code>\u62f7\u8d1d\u5230<code>C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin<\/code>\u6587\u4ef6\u5939\u4e2d\uff0c\u91cd\u65b0\u7f16\u8bd1\u5373\u53ef\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5982\u679c\u6253\u5305\u597d\u7684pyd\u4e0d\u80fd\u6b63\u5e38import\u4f7f\u7528\uff0c\u53ef\u4ee5\u67e5\u770b\u62a5\u9519\u4e2d\u63d0\u793a\u7f3a\u5931\u7684\u6a21\u5757\uff0c\u5982\u679c\u4f9d\u7136\u67e5\u4e0d\u5230\uff0c\u53ef\u4ee5\u8bd5\u8bd5<a href=\"https:\/\/www.yumefx.com\/files\/Depends_find%20lost%20dll.exe\">Depends\u8f6f\u4ef6<\/a>\u67e5\u770b\u7f3a\u5931\u7684dll\u3002<\/p>\n<p>\u00a0<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5b64\u72ec\u548c\u5bc2\u5bde\u4e0d\u4e00\u6837\uff0c<br \/>\u5bc2\u5bde\u4f1a\u53d1\u614c\uff0c<br \/>\u5b64\u72ec\u5219\u662f\u9971\u6ee1\u7684\u3002<\/p>\n<p style=\"text-align: right;\">\u2014\u2014\u848b\u52cb<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4ee5\u524d\u66f4\u65b0\u8fc7\u4e00\u7bc7pyinstaller\u2014py\u811a\u672c\u6253\u5305\u6210exe\uff0c\u8bf4\u7684\u662f\u5c06Python\u811a\u672c\u6253\u5305\u6210exe\u53ef\u6267\u884c\u6587 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5009,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,4],"tags":[37,14,25],"_links":{"self":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/5005"}],"collection":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5005"}],"version-history":[{"count":0,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/5005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/media\/5009"}],"wp:attachment":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}