{"id":14655,"date":"2023-03-06T14:19:45","date_gmt":"2023-03-06T06:19:45","guid":{"rendered":"http:\/\/139.9.1.231\/?p=14655"},"modified":"2023-03-07T08:40:07","modified_gmt":"2023-03-07T00:40:07","slug":"python-m","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2023\/03\/06\/python-m\/","title":{"rendered":"Python \u4e2d -m \u53c2\u6570\u7684\u7528\u6cd5"},"content":{"rendered":"\n<p class=\"has-bright-blue-background-color has-background\">      <strong>\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528 Python \u65f6\uff0c\u5b83\u53ef\u4ee5\u63a5\u6536\u5927\u7ea6 20 \u4e2a\u9009\u9879\uff08option\uff09\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>python &#91;-bBdEhiIOqsSuvVWx?] &#91;-c command | -m module-name | script | - ] &#91;args]<\/strong><\/code><\/pre>\n\n\n\n<p>\u7528\u201c&#8211;help\u201d\u6765\u770b\u770b\u5b83\u7684\u89e3\u91ca\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-9-1024x640.png\" alt=\"\" class=\"wp-image-14663\" width=\"579\" height=\"362\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-9-1024x640.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-9-300x187.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-9-768x480.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-9.png 1042w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/figure><\/div>\n\n\n\n<p>-m mod run library module as a script (terminates option list)<\/p>\n\n\n\n<p>&#8220;mod&#8221;\u662f\u201cmodule\u201d\u7684\u7f29\u5199\uff0c\u5373\u201c-m\u201d\u9009\u9879\u540e\u9762\u7684\u5185\u5bb9\u662f module\uff08\u6a21\u5757\uff09\uff0c\u5176\u4f5c\u7528\u662f\u628a\u6a21\u5757\u5f53\u6210\u811a\u672c\u6765\u8fd0\u884c\u3002<\/p>\n\n\n\n<p>\u201cterminates option list\u201d\u610f\u5473\u7740\u201c-m\u201d\u4e4b\u540e\u7684\u5176\u5b83\u9009\u9879\u4e0d\u8d77\u4f5c\u7528\uff0c\u5728\u8fd9\u70b9\u4e0a\u5b83\u8ddf\u201c-c\u201d\u662f\u4e00\u6837\u7684\uff0c\u90fd\u662f\u201c\u7ec8\u6781\u9009\u9879\u201d\u3002\u5b98\u65b9\u628a\u5b83\u4eec\u5b9a\u4e49\u4e3a\u201c\u63a5\u53e3\u9009\u9879\u201d\uff08Interface options\uff09\uff0c\u9700\u8981\u533a\u522b\u4e8e\u5176\u5b83\u7684\u666e\u901a\u9009\u9879\u6216\u901a\u7528\u9009\u9879\u3002<\/p>\n\n\n\n<h2>m \u9009\u9879\u7684\u4e94\u4e2a\u5178\u578b\u7528\u6cd5<\/h2>\n\n\n\n<p>Python \u4e2d\u6709\u5f88\u591a\u4f7f\u7528 -m \u9009\u9879\u7684\u573a\u666f\uff0c\u76f8\u4fe1\u5927\u5bb6\u53ef\u80fd\u4f1a\u7528\u5230\u6216\u8005\u770b\u89c1\u8fc7\uff0c\u6211\u5728\u8fd9\u91cc\u60f3\u5206\u4eab 5 \u4e2a\u3002<\/p>\n\n\n\n<p>\u5728 Python3 \u4e2d\uff0c\u53ea\u9700\u4e00\u884c\u547d\u4ee4\u5c31\u80fd\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684 HTTP \u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m http.server 8000\n\n<em># \u6ce8:\u5728 Python2 \u4e2d\u662f\u8fd9\u6837<\/em>\npython -m SimpleHTTPServer 8000\u590d\u5236\u4ee3\u7801<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c464cd6a52e~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u6267\u884c\u540e\uff0c\u5728\u672c\u673a\u6253\u5f00\u201c<a href=\"https:\/\/link.juejin.cn\/?target=http%3A%2F%2Flocalhost%3A8000%2F\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/localhost:8000<\/a>\u201d\uff0c\u6216\u8005\u5728\u5c40\u57df\u7f51\u5185\u7684\u5176\u5b83\u673a\u5668\u4e0a\u6253\u5f00\u201chttp:\/\/\u672c\u673aip:8000\u201d\uff0c\u5c31\u80fd\u8bbf\u95ee\u5230\u6267\u884c\u76ee\u5f55\u4e0b\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\u4e0b\u56fe\u5c31\u662f\u6211\u672c\u673a\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c46b6a25b26~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u4e0e\u6b64\u7c7b\u4f3c\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4e00\u884c\u547d\u4ee4\u201cpython -m pydoc -p xxx\u201d\uff0c\u5c31\u80fd\u751f\u6210 HTML \u683c\u5f0f\u7684\u5b98\u65b9\u5e2e\u52a9\u6587\u6863\uff0c\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c46dfa8061a~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u4e0a\u9762\u7684\u547d\u4ee4\u6267\u884c\u4e86 pydoc \u6a21\u5757\uff0c\u4f1a\u5728 9000 \u7aef\u53e3\u542f\u52a8\u4e00\u4e2a http \u670d\u52a1\uff0c\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\uff0c\u6211\u7684\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c48044fd314~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p class=\"has-light-blue-background-color has-background\">        <strong>\u5b83\u7684\u7b2c\u4e09\u4e2a\u5e38\u89c1\u7528\u6cd5\u662f\u6267\u884c pdb \u7684\u8c03\u8bd5\u547d\u4ee4\u201cpython -m pdb xxx.py\u201d\uff0c\u4ee5\u8c03\u8bd5\u6a21\u5f0f\u6765\u6267\u884c\u201cxxx.py\u201d\u811a\u672c\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c48334aa752~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>       <strong>\u7b2c\u56db\u4e2a\u540c\u6837\u633a\u6709\u7528\u7684\u573a\u666f\u662f\u7528 timeit \u5728\u547d\u4ee4\u884c\u4e2d\u6d4b\u8bd5\u4e00\u5c0f\u6bb5\u4ee3\u7801\u7684\u8fd0\u884c\u65f6\u95f4\u3002\u4ee5\u4e0b\u7684 3 \u6bb5\u4ee3\u7801\uff0c\u7528\u4e0d\u540c\u7684\u65b9\u5f0f\u62fc\u63a5 \u201c0-1-2-\u2026\u2026-99\u201d \u6570\u5b57\u4e32\u3002\u53ef\u4ee5\u76f4\u89c2\u5730\u770b\u51fa\u5b83\u4eec\u7684\u6548\u7387\u5dee\u5f02\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c48c1e29277~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p class=\"has-light-pink-background-color has-background\"><strong>\u6700\u540e\uff0c\u8fd8\u6709\u4e00\u79cd\u5e38\u5e38\u88ab\u4eba\u5ffd\u7565\u7684\u573a\u666f\uff1a\u201cpython -m pip install xxx\u201d\u3002\u6211\u4eec\u53ef\u80fd\u4f1a\u4e60\u60ef\u6027\u5730\u4f7f\u7528\u201cpip install xxx\u201d\uff0c\u6216\u8005\u505a\u4e86\u7248\u672c\u533a\u5206\u65f6\u7528\u201cpip3 install xxx\u201d\uff0c\u603b\u4e4b\u4e0d\u5728\u524d\u9762\u7528\u201cpython -m\u201d\u505a\u6307\u5b9a\u3002\u4f46\u8fd9\u79cd\u5199\u6cd5\u53ef\u80fd\u4f1a\u51fa\u95ee\u9898\u3002<\/strong><\/p>\n\n\n\n<p>\u5f88\u5de7\u5408\u7684\u662f\uff0c\u5728\u672c\u6708\u521d\uff082019.11.01\uff09\uff0cPython \u7684\u6838\u5fc3\u5f00\u53d1\u8005\u3001<a href=\"https:\/\/link.juejin.cn\/?target=https%3A%2F%2Fmp.weixin.qq.com%2Fs%2FhjcVFaGgI_Ww--Ktv7XP9Q\" target=\"_blank\" rel=\"noreferrer noopener\">\u7b2c\u4e00\u5c4a\u6307\u5bfc\u59d4\u5458\u4f1a<\/a>&nbsp;\u4e94\u4eba\u6210\u5458\u4e4b\u4e00\u7684 Brett Cannon \u4e13\u95e8\u5199\u4e86\u4e00\u7bc7\u535a\u5ba2\u300a<a href=\"https:\/\/link.juejin.cn\/?target=https%3A%2F%2Fsnarky.ca%2Fwhy-you-should-use-python-m-pip\" target=\"_blank\" rel=\"noreferrer noopener\">Why you should use &#8220;python -m pip&#8221;&nbsp;<\/a>\u300b\uff0c\u63d0\u51fa\u5e94\u8be5\u4f7f\u7528\u201cpython -m pip\u201d\u7684\u65b9\u5f0f\uff0c\u5e76\u505a\u4e86\u8be6\u7ec6\u7684\u89e3\u91ca\u3002<\/p>\n\n\n\n<p><strong>\u4ed6\u7684\u4e3b\u8981\u89c2\u70b9\u662f\uff1a\u5728\u5b58\u5728\u591a\u4e2a Python \u7248\u672c\u7684\u73af\u5883\u4e2d\uff0c\u8fd9\u79cd\u5199\u6cd5\u53ef\u4ee5\u7cbe\u786e\u5730\u63a7\u5236\u4e09\u65b9\u5e93\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002\u4f8b\u5982\u7528\u201cpython3.8 -m pip\u201d\uff0c\u53ef\u4ee5\u660e\u786e\u6307\u5b9a\u7ed9 3.8 \u7248\u672c\u5b89\u88c5\uff0c\u800c\u4e0d\u4f1a\u6df7\u6dc6\u6210\u5176\u5b83\u7684\u7248\u672c\u3002<\/strong><\/p>\n\n\n\n<h2>-m \u9009\u9879\u7684\u4e24\u79cd\u539f\u7406\u89e3\u6790<\/h2>\n\n\n\n<p>\u770b\u4e86\u524d\u9762\u7684\u51e0\u79cd\u5178\u578b\u7528\u6cd5\uff0c\u4f60\u662f\u5426\u5f00\u59cb\u597d\u5947\uff1a<strong>\u201c-m\u201d\u662f\u600e\u4e48\u8fd0\u4f5c\u7684\uff1f\u5b83\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f<\/strong><\/p>\n\n\n\n<p>\u5bf9\u4e8e\u201cpython -m name\u201d\uff0c\u4e00\u53e5\u8bdd\u89e3\u91ca\uff1a<strong>Python \u4f1a\u68c0\u7d22<\/strong><strong><code>sys.path<\/code><\/strong><strong>&nbsp;\uff0c\u67e5\u627e\u540d\u5b57\u4e3a\u201cname\u201d\u7684\u6a21\u5757\u6216\u8005\u5305\uff08\u542b\u547d\u540d\u7a7a\u95f4\u5305\uff09\uff0c\u5e76\u5c06\u5176\u5185\u5bb9\u5f53\u6210\u201c__main__\u201d\u6a21\u5757\u6765\u6267\u884c\u3002<\/strong><\/p>\n\n\n\n<h3>1\u3001\u5bf9\u4e8e\u666e\u901a\u6a21\u5757<\/h3>\n\n\n\n<p>\u4ee5\u201c.py\u201d\u4e3a\u540e\u7f00\u7684\u6587\u4ef6\u5c31\u662f\u4e00\u4e2a\u6a21\u5757\uff0c\u5728\u201c-m\u201d\u4e4b\u540e\u4f7f\u7528\u65f6\uff0c\u53ea\u9700\u8981\u4f7f\u7528\u6a21\u5757\u540d\uff0c\u4e0d\u9700\u8981\u5199\u51fa\u540e\u7f00\uff0c\u4f46\u524d\u63d0\u662f\u8be5\u6a21\u5757\u540d\u662f\u6709\u6548\u7684\uff0c\u4e14\u4e0d\u80fd\u662f\u7528 C \u8bed\u8a00\u5199\u6210\u7684\u6a21\u5757\u3002<\/p>\n\n\n\n<p>\u5728\u201c-m\u201d\u4e4b\u540e\uff0c\u5982\u679c\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u6a21\u5757\u540d\uff0c\u5219\u4f1a\u62a5\u9519\u201cNo module named xxx\u201d\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u4e00\u4e2a\u5e26\u540e\u7f00\u7684\u6a21\u5757\uff0c\u5219\u9996\u5148\u4f1a\u5bfc\u5165\u8be5\u6a21\u5757\uff0c\u7136\u540e\u53ef\u80fd\u62a5\u9519\uff1aError while finding module specification for &#8216;xxx.py&#8217; (AttributeError: module &#8216;xxx&#8217; has no attribute &#8216;__path__&#8217;\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c494351b189~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u666e\u901a\u6a21\u5757\uff0c\u6709\u65f6\u5019\u8fd9\u4e24\u79cd\u5199\u6cd5\u8868\u9762\u770b\u8d77\u6765\u662f\u7b49\u6548\u7684\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c497224edcf~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u4e24\u79cd\u5199\u6cd5\u90fd\u4f1a\u628a\u5b9a\u4f4d\u5230\u7684\u6a21\u5757\u811a\u672c\u5f53\u6210\u4e3b\u7a0b\u5e8f\u5165\u53e3\u6765\u6267\u884c\uff0c\u5373\u5728\u6267\u884c\u65f6\uff0c\u8be5\u811a\u672c\u7684<code>__name__<\/code>&nbsp;\u90fd\u662f\u201d__main__\u201c\uff0c\u8ddf import \u5bfc\u5165\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\u3002<\/p>\n\n\n\n<p>\u4f46\u5b83\u7684\u524d\u63d0\u662f\uff1a\u5728\u6267\u884c\u76ee\u5f55\u4e2d\u5b58\u5728\u7740\u201ctest.py\u201d\uff0c\u4e14\u53ea\u6709\u552f\u4e00\u7684\u201ctest\u201d\u6a21\u5757\u3002\u5bf9\u4e8e\u672c\u4f8b\uff0c\u5982\u679c\u6362\u4e00\u4e2a\u76ee\u5f55\u6267\u884c\u7684\u8bdd\uff0c\u201cpython test.py\u201d\u5f53\u7136\u4f1a\u62a5\u627e\u4e0d\u5230\u6587\u4ef6\u7684\u9519\u8bef\uff0c\u7136\u800c\uff0c\u201cpython -m test\u201d\u5374\u4e0d\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u89e3\u91ca\u5668\u5728\u904d\u5386<code>sys.path<\/code>&nbsp;\u65f6\u53ef\u4ee5\u627e\u5230\u540c\u540d\u7684\u201ctest\u201d\u6a21\u5757\uff0c\u5e76\u4e14\u6267\u884c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c4b4f03950d~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u7531\u6b64\u5dee\u5f02\uff0c\u6211\u4eec\u5176\u5b9e\u53ef\u4ee5\u603b\u7ed3\u51fa\u201c-m\u201d\u7684\u7528\u6cd5\uff1a<strong>\u5df2\u77e5\u4e00\u4e2a\u6a21\u5757\u7684\u540d\u5b57\uff0c\u4f46\u4e0d\u77e5\u9053\u5b83\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u90a3\u4e48\u4f7f\u7528\u201c-m\u201d\u5c31\u610f\u5473\u7740\u4ea4\u7ed9\u89e3\u91ca\u5668\u81ea\u884c\u67e5\u627e\uff0c\u82e5\u627e\u5230\uff0c\u5219\u5f53\u6210\u811a\u672c\u6267\u884c\u3002<\/strong><\/p>\n\n\n\n<p>\u4ee5\u524d\u6587\u7684\u201cpython -m http.server 8000\u201d\u4e3a\u4f8b\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u627e\u5230\u201cserver\u201d\u6a21\u5757\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u7136\u540e\u6267\u884c\uff0c\u5c3d\u7ba1\u8fd9\u6837\u4f1a\u53d8\u5f97\u5f88\u9ebb\u70e6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c4bbea6368a~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u90a3\u4e48\uff0c\u201c-m\u201d\u65b9\u5f0f\u4e0e\u76f4\u63a5\u8fd0\u884c\u811a\u672c\u76f8\u6bd4\uff0c\u5728\u5b9e\u73b0\u4e0a\u6709\u4ec0\u4e48\u4e0d\u540c\u5462\uff1f<\/p>\n\n\n\n<ul><li>\u76f4\u63a5\u8fd0\u884c\u811a\u672c\u65f6\uff0c\u76f8\u5f53\u4e8e\u7ed9\u51fa\u4e86\u811a\u672c\u7684\u5b8c\u6574\u8def\u5f84\uff08\u4e0d\u7ba1\u662f\u7edd\u5bf9\u8def\u5f84\u8fd8\u662f\u76f8\u5bf9\u8def\u5f84\uff09\uff0c\u89e3\u91ca\u5668\u6839\u636e<strong>\u6587\u4ef6\u7cfb\u7edf\u7684\u67e5\u627e\u673a\u5236\uff0c<\/strong>&nbsp;\u5b9a\u4f4d\u5230\u8be5\u811a\u672c\uff0c\u7136\u540e\u6267\u884c<\/li><li>\u4f7f\u7528\u201c-m\u201d\u65b9\u5f0f\u65f6\uff0c\u89e3\u91ca\u5668\u9700\u8981\u5728\u4e0d import \u7684\u60c5\u51b5\u4e0b\uff0c\u5728<strong>\u6240\u6709\u6a21\u5757\u547d\u540d\u7a7a\u95f4<\/strong>&nbsp;\u4e2d\u67e5\u627e\uff0c\u5b9a\u4f4d\u5230\u811a\u672c\u7684\u8def\u5f84\uff0c\u7136\u540e\u6267\u884c\u3002\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u89e3\u91ca\u5668\u4f1a\u501f\u52a9\u4e24\u4e2a\u6a21\u5757\uff1a<code>pkgutil<\/code>&nbsp;\u548c&nbsp;<code>runpy<\/code>&nbsp;\uff0c\u524d\u8005\u7528\u6765\u83b7\u53d6\u6240\u6709\u7684\u6a21\u5757\u5217\u8868\uff0c\u540e\u8005\u6839\u636e\u6a21\u5757\u540d\u6765\u5b9a\u4f4d\u5e76\u6267\u884c\u811a\u672c<\/li><\/ul>\n\n\n\n<h3>2\u3001\u5bf9\u4e8e\u5305\u5185\u6a21\u5757<\/h3>\n\n\n\n<p>\u5982\u679c\u201c-m\u201d\u4e4b\u540e\u8981\u6267\u884c\u7684\u662f\u4e00\u4e2a\u5305\uff0c\u90a3\u4e48\u89e3\u91ca\u5668\u7ecf\u8fc7\u524d\u9762\u63d0\u5230\u7684\u67e5\u627e\u8fc7\u7a0b\uff0c\u5148\u5b9a\u4f4d\u5230\u8be5\u5305\uff0c\u7136\u540e\u4f1a\u53bb\u6267\u884c\u5b83\u7684\u201c__main__\u201d\u5b50\u6a21\u5757\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u5305\u76ee\u5f55\u4e0b\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u201c__main__.py\u201d\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0c\u5047\u8bbe\u6709\u4e2a\u5305\u7684\u540d\u79f0\u662f\u201cpname\u201d\uff0c\u90a3\u4e48\uff0c<strong>\u201cpython -m pname\u201d\uff0c\u5176\u5b9e\u5c31\u7b49\u6548\u4e8e\u201cpython -m pname.__main__\u201d\u3002<\/strong><\/p>\n\n\n\n<p>\u4ecd\u4ee5\u524d\u6587\u521b\u5efa HTTP \u670d\u52a1\u4e3a\u4f8b\uff0c\u201chttp\u201d\u662f Python \u5185\u7f6e\u7684\u4e00\u4e2a\u5305\uff0c\u5b83\u6ca1\u6709\u201c__main__.py\u201d\u6587\u4ef6\uff0c\u6240\u4ee5\u4f7f\u7528\u201c-m\u201d\u65b9\u5f0f\u6267\u884c\u65f6\uff0c\u5c31\u4f1a\u62a5\u9519\uff1aNo module named http.__main__; &#8216;http&#8217; is a package and cannot be directly executed\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c4c56c408bb~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u4f5c\u4e3a\u5bf9\u6bd4\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u770b\u524d\u6587\u63d0\u5230\u7684 pip\uff0c\u5b83\u4e5f\u662f\u4e00\u4e2a\u5305\uff0c\u4e3a\u4ec0\u4e48\u201cpython -m pip\u201d\u7684\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u7528\u5462\uff1f\u5f53\u7136\u662f\u56e0\u4e3a\u5b83\u6709\u201c__main__.py\u201d\u6587\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/p1-jj.byteimg.com\/tos-cn-i-t2oaga2asx\/gold-user-assets\/2019\/11\/10\/16e53c4e171b0cc7~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp\" alt=\"\" title=\"\"\/><\/figure>\n\n\n\n<p>\u201cpython -m pip\u201d\u5b9e\u9645\u4e0a\u6267\u884c\u7684\u5c31\u662f\u8fd9\u4e2a\u201c__main__.py\u201d\u6587\u4ef6\uff0c\u5b83\u4e3b\u8981\u4f5c\u4e3a\u4e00\u4e2a\u8c03\u7528\u5165\u53e3\uff0c\u8c03\u7528\u4e86\u6838\u5fc3\u7684&#8221;pip._internal.main&#8221;\u3002<\/p>\n\n\n\n<p>http \u5305\u56e0\u4e3a\u6ca1\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u5165\u53e3\u6a21\u5757\uff0c\u6240\u4ee5\u91c7\u7528\u4e86\u201cpython -m \u5305.\u6a21\u5757\u201d\u7684\u65b9\u5f0f\uff0c\u800c pip \u5305\u56e0\u4e3a\u6709\u7edf\u4e00\u7684\u5165\u53e3\u6a21\u5757\uff0c\u6240\u4ee5\u52a0\u4e86\u4e00\u4e2a\u201c__main__.py\u201d\u6587\u4ef6\uff0c\u6700\u540e\u53ea\u9700\u8981\u5199\u201cpython -m \u5305\u201d\uff0c\u7b80\u660e\u76f4\u89c2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528 Python \u65f6\uff0c\u5b83\u53ef\u4ee5\u63a5\u6536\u5927\u7ea6 20 \u4e2a\u9009\u9879\uff08option\uff09\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a \u7528\u201c&#038;#821 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2023\/03\/06\/python-m\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Python \u4e2d -m \u53c2\u6570\u7684\u7528\u6cd5<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14655"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=14655"}],"version-history":[{"count":19,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14655\/revisions"}],"predecessor-version":[{"id":14677,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14655\/revisions\/14677"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=14655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=14655"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=14655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}