{"id":204551,"date":"2025-05-29T09:55:07","date_gmt":"2025-05-29T01:55:07","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204551\/"},"modified":"2025-05-29T09:55:07","modified_gmt":"2025-05-29T01:55:07","slug":"python-%e4%b8%adno-module-named-json%e9%94%99%e8%af%af%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204551\/","title":{"rendered":"Python \u4e2d\u201cNo module named &#8216;json&#8217;\u201d\u9519\u8bef\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u4e2d\u201cNo module named &#8216;json&#8217;\u201d\u9519\u8bef\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300aPython \u4e2d\u201cNo module named &#8216;json&#8217;\u201d\u9519\u8bef\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/173121843567304c0396dd4.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5bfc\u5165json\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728\u4f7f\u7528python\u7684import json\u65f6\uff0c\u521d\u5b66\u8005\u7ecf\u5e38\u4f1a\u9047\u5230\u9519\u8bef\u3002\u672c\u6587\u5c06\u9488\u5bf9\u4e00\u4e2a\u5e38\u89c1\u7684\u9519\u8bef\u8fdb\u884c\u89e3\u7b54\u3002<\/p>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a<\/p>\n<p>\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u5728\u5bfc\u5165json\u6a21\u5757\u65f6\uff0c\u51fa\u73b0&#8221;no module named &#8216;json'&#8221;\u9519\u8bef\u3002<\/p>\n<p>\u89e3\u7b54\uff1a<\/p>\n<p>\u8be5\u9519\u8bef\u63d0\u793a\u8868\u660e\u627e\u4e0d\u5230\u540d\u4e3a&#8221;json&#8221;\u7684\u6a21\u5757\u3002\u89e3\u51b3\u65b9\u6cd5\u662f\uff1a<\/p>\n<ol>\n<li><strong>\u68c0\u67e5\u5b89\u88c5\u72b6\u6001\uff1a<\/strong>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c&#8221;pip install json&#8221;\u3002\u8fd9\u5c06\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5json\u6a21\u5757\uff0c\u5982\u679c\u6a21\u5757\u5df2\u5b89\u88c5\uff0c\u5219\u65e0\u9700\u6267\u884c\u6b64\u6b65\u9aa4\u3002<\/li>\n<li><strong>\u786e\u8ba4\u5e93\u540d\u79f0\uff1a<\/strong>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u6b63\u786e\u7684\u5e93\u540d\u79f0\u3002&#8221;load&#8221;\u662fjson\u6a21\u5757\u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u4e0d\u80fd\u76f4\u63a5\u5bfc\u5165\u3002\u6b63\u786e\u7684\u5bfc\u5165\u8bed\u53e5\u4e3a\uff1a<\/li>\n<\/ol>\n<pre>import json<\/pre>\n<ol>\n<li><strong>\u4f7f\u7528\u6b63\u786e\u7684\u51fd\u6570\uff1a<\/strong>load\u548cloads\u662fjson\u6a21\u5757\u4e2d\u4e0d\u540c\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u52a0\u8f7d\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u5982\u679c\u8981\u52a0\u8f7d\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f7f\u7528loads()\u51fd\u6570\uff1b\u5982\u679c\u8981\u52a0\u8f7d\u6587\u4ef6\uff0c\u8bf7\u4f7f\u7528load()\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p>\u6839\u636e\u7ed9\u5b9a\u7684\u63d0\u793a\uff0c\u8be5\u95ee\u9898\u53ef\u80fd\u662f\u7528\u6237\u5c06load()\u51fd\u6570\u8bef\u5199\u4e3aloads()\u51fd\u6570\u3002\u56e0\u6b64\uff0c\u6b63\u786e\u7684\u4ee3\u7801\u5e94\u4e3a\uff1a<\/p>\n<pre>import json\n\nwith open('data.json') as f:\n    data = json.load(f)  # \u4ece\u6587\u4ef6\u4e2d\u52a0\u8f7dJSON\u6570\u636e<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d\u201cNo modu&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204551","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204551"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204551\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}