{"id":957141,"date":"2024-12-27T02:52:40","date_gmt":"2024-12-26T18:52:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/957141.html"},"modified":"2024-12-27T02:52:44","modified_gmt":"2024-12-26T18:52:44","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e5%ae%89%e8%a3%85dlib","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/957141.html","title":{"rendered":"\u5982\u4f55\u5728python\u5b89\u88c5dlib"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100544\/7a484911-0e5d-4362-b934-1b72366b084a.webp\" alt=\"\u5982\u4f55\u5728python\u5b89\u88c5dlib\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u5b89\u88c5dlib\uff0c\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\u3001\u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u5b89\u88c5\u4ee5\u53ca\u4f7f\u7528Anaconda\u8fdb\u884c\u5b89\u88c5\u3002<strong>\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff0c\u56e0\u4e3a\u5b83\u6700\u4e3a\u7b80\u5355\u548c\u76f4\u63a5\uff0c\u9002\u5408\u5927\u591a\u6570\u7528\u6237\u7684\u9700\u6c42<\/strong>\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5c24\u5176\u662f\u5728Windows\u7cfb\u7edf\u4e0a\uff0c\u5b89\u88c5dlib\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u6311\u6218\uff0c\u8fd9\u65f6\u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u6216\u4f7f\u7528Anaconda\u53ef\u80fd\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u5b89\u88c5\u6b65\u9aa4\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528PIP\u5b89\u88c5dlib<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u51c6\u5907Python\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c<code>python --version<\/code>\u548c<code>pip --version<\/code>\u6765\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u5df2\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u8bf7\u5148\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\uff0cpip\u901a\u5e38\u4f1a\u4e0ePython\u4e00\u8d77\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5CMake<\/strong><\/p>\n<\/p>\n<p><p>dlib\u4f9d\u8d56\u4e8eCMake\u8fdb\u884c\u6784\u5efa\uff0c\u56e0\u6b64\u9700\u8981\u5148\u5b89\u88c5CMake\u3002\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u4eceCMake\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002\u5bf9\u4e8eLinux\u548cmacOS\u7528\u6237\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5\uff0c\u4f8b\u5982\u5728Ubuntu\u4e0a\u8fd0\u884c<code>sudo apt-get install cmake<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Boost\u5e93\uff08\u4ec5\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u9700\u8981\uff09<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u7248\u672c\u7684dlib\u4e2d\uff0c\u53ef\u80fd\u4f1a\u8981\u6c42\u5b89\u88c5Boost\u5e93\u3002Boost\u5e93\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684C++\u5e93\u96c6\u5408\uff0c\u5982\u679c\u4f60\u7684\u9879\u76ee\u6216\u8005dlib\u7248\u672c\u9700\u8981\u5b83\uff0c\u786e\u4fdd\u5b89\u88c5\u8be5\u5e93\u3002\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5Boost\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pip\u5b89\u88c5dlib<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install dlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0cpip\u5c06\u81ea\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5dlib\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u542f\u52a8Python\u89e3\u91ca\u5668\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dlib<\/p>\n<p>print(dlib.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u8bf4\u660edlib\u5df2\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u5b89\u88c5dlib<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7ddlib\u6e90\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<p><p>\u4ecedlib\u7684GitHub\u4ed3\u5e93\u514b\u9686\u6700\u65b0\u7684\u6e90\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">git clone https:\/\/github.com\/davisking\/dlib.git<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u5e76\u5b89\u88c5dlib<\/strong><\/p>\n<\/p>\n<p><p>\u8fdb\u5165\u4e0b\u8f7d\u7684dlib\u76ee\u5f55\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6784\u5efa\u548c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd dlib<\/p>\n<p>python setup.py install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u53ef\u80fd\u9700\u8981\u6307\u5b9aVisual Studio\u7684\u8def\u5f84\uff0c\u6216\u8005\u5728CMake\u4e2d\u6307\u660e\u7f16\u8bd1\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u53ef\u80fd\u7684\u7f16\u8bd1\u9519\u8bef<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u9047\u5230\u9519\u8bef\uff0c\u901a\u5e38\u4e0e\u7f3a\u5c11\u4f9d\u8d56\u9879\u6216\u73af\u5883\u914d\u7f6e\u6709\u5173\u3002\u68c0\u67e5\u9519\u8bef\u4fe1\u606f\uff0c\u5b89\u88c5\u7f3a\u5c11\u7684\u4f9d\u8d56\uff0c\u6216\u8005\u8c03\u6574\u7f16\u8bd1\u914d\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528Anaconda\u5b89\u88c5dlib<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u7684Conda\u73af\u5883\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u907f\u514d\u4e0e\u5176\u4ed6\u9879\u76ee\u7684\u4f9d\u8d56\u51b2\u7a81\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Conda\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda create -n myenv python=3.8<\/p>\n<p>conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5dlib<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528conda-forge\u901a\u9053\u5b89\u88c5dlib\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install -c conda-forge dlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u540c\u6837\u53ef\u4ee5\u901a\u8fc7Python\u89e3\u91ca\u5668\u6765\u68c0\u67e5dlib\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dlib<\/p>\n<p>print(dlib.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u8bd1\u9519\u8bef<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u8bd1\u9519\u8bef\u901a\u5e38\u4e0e\u7f3a\u5c11CMake\u3001Boost\u6216\u5176\u4ed6\u5e93\u6709\u5173\u3002\u68c0\u67e5\u5b89\u88c5\u65e5\u5fd7\uff0c\u5e76\u6839\u636e\u63d0\u793a\u5b89\u88c5\u76f8\u5e94\u7684\u5de5\u5177\u6216\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5185\u5b58\u4e0d\u8db3<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5185\u5b58\u4e0d\u8db3\u7684\u7cfb\u7edf\u4e0a\uff08\u4f8b\u5982\u865a\u62df\u673a\uff09\uff0c\u7f16\u8bd1dlib\u53ef\u80fd\u4f1a\u5931\u8d25\u3002\u53ef\u4ee5\u5c1d\u8bd5\u589e\u52a0\u865a\u62df\u673a\u7684\u5185\u5b58\u6216\u5728\u7269\u7406\u673a\u4e0a\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Python\u7248\u672c\u4e0d\u517c\u5bb9<\/strong><\/p>\n<\/p>\n<p><p>\u786e\u4fdd\u4f7f\u7528\u7684Python\u7248\u672c\u4e0edlib\u517c\u5bb9\uff0c\u901a\u5e38\u5efa\u8bae\u4f7f\u7528Python 3.6\u53ca\u4ee5\u4e0a\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u5728Python\u4e2d\u6210\u529f\u5b89\u88c5dlib\u3002\u6839\u636e\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u548cPython\u73af\u5883\uff0c\u53ef\u80fd\u9700\u8981\u505a\u51fa\u4e00\u4e9b\u8c03\u6574\uff0c\u4f46\u6574\u4f53\u6d41\u7a0b\u662f\u76f8\u4f3c\u7684\u3002\u5982\u679c\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u67e5\u9605dlib\u7684\u5b98\u65b9\u6587\u6863\u6216\u793e\u533a\u8bba\u575b\u4ee5\u83b7\u53d6\u66f4\u591a\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u7684\u7cfb\u7edf\u662f\u5426\u652f\u6301dlib\u7684\u5b89\u88c5\uff1f<\/strong><br \/>\u5728\u5b89\u88c5dlib\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u6ee1\u8db3\u5176\u4f9d\u8d56\u8981\u6c42\u3002dlib\u4f9d\u8d56\u4e8eCMake\u548cBoost\u5e93\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>cmake --version<\/code>\u548c<code>boost --version<\/code>\u6765\u68c0\u67e5\u8fd9\u4e9b\u5e93\u7684\u5b89\u88c5\u60c5\u51b5\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u5efa\u8bae\u5148\u901a\u8fc7\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5b89\u88c5dlib\u65f6\u9047\u5230\u7f16\u8bd1\u9519\u8bef\u8be5\u5982\u4f55\u5904\u7406\uff1f<\/strong><br \/>\u7f16\u8bd1\u9519\u8bef\u901a\u5e38\u4e0e\u7f3a\u5c11\u4f9d\u8d56\u6216\u73af\u5883\u914d\u7f6e\u4e0d\u5f53\u6709\u5173\u3002\u4f60\u53ef\u4ee5\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u5b89\u88c5CMake\u548cBoost\u5e93\uff0c\u5e76\u786e\u4fdd\u4f60\u7684Python\u7248\u672c\u4e0edlib\u517c\u5bb9\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u66f4\u65b0pip\u548csetuptools\u4e5f\u80fd\u89e3\u51b3\u4e00\u4e9b\u95ee\u9898\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u547d\u4ee4<code>pip install --upgrade pip setuptools<\/code>\u8fdb\u884c\u66f4\u65b0\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u63a8\u8350\u7684\u66ff\u4ee3\u65b9\u6cd5\u6765\u5b89\u88c5dlib\uff1f<\/strong><br \/>\u5982\u679c\u4f60\u5728\u901a\u8fc7\u6e90\u4ee3\u7801\u7f16\u8bd1dlib\u65f6\u9047\u5230\u56f0\u96be\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u5305\u3002\u901a\u8fc7Anaconda\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5dlib\uff0c\u547d\u4ee4\u662f<code>conda install -c conda-forge dlib<\/code>\u3002\u8fd9\u79cd\u65b9\u6cd5\u901a\u5e38\u907f\u514d\u4e86\u7f16\u8bd1\u95ee\u9898\uff0c\u5e76\u4e14\u80fd\u8282\u7701\u5b89\u88c5\u65f6\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b89\u88c5dlib\uff0c\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\u3001\u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u5b89\u88c5\u4ee5\u53ca [&hellip;]","protected":false},"author":3,"featured_media":957149,"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\/957141"}],"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=957141"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957141\/revisions"}],"predecessor-version":[{"id":957151,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957141\/revisions\/957151"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/957149"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=957141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=957141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=957141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}