{"id":50291,"date":"2024-12-03T11:16:37","date_gmt":"2024-12-03T03:16:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50291\/"},"modified":"2024-12-03T11:16:37","modified_gmt":"2024-12-03T03:16:37","slug":"pycharm-%e4%b8%ad%e8%b0%83%e7%94%a8-nltk-%e5%8c%85%e6%97%b6%e6%8a%a5%e9%94%99%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-attributeerror-module-nltk-has-no-attribute-word_tokenize%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50291\/","title":{"rendered":"PyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>PyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f<\/h1>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241116\/173175143067386e0697917.jpg\" class=\"aligncenter\" title=\"PyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f\u63d2\u56fe\" alt=\"PyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>pycharm\u8c03\u7528nltk\u5305\u65f6\u62a5\u9519<\/strong><\/p>\n<p>\u5728pycharm\u4e2d\u5b89\u88c5nltk\u5305\u540e\uff0c\u8c03\u7528\u5176\u529f\u80fd\u65f6\u9047\u5230\u4ee5\u4e0b\u62a5\u9519\uff1a<\/p>\n<pre>attributeerror: module 'nltk' has no attribute 'word_tokenize'<\/pre>\n<p><strong>\u89e3\u51b3\u6b65\u9aa4<\/strong><\/p>\n<p>\u6839\u636e\u63d0\u4f9b\u7684\u6587\u6863\uff0cnltk\u7684\u6700\u65b0\u7248\u672c\u5df2\u5f03\u7528word_tokenize\u65b9\u6cd5\uff0c\u5efa\u8bae\u4f7f\u7528nltk.tokenize.word_tokenize\u51fd\u6570\u66ff\u4ee3\u3002\u5c06\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u8c03\u7528\u7684word_tokenize\u65b9\u6cd5\u66ff\u6362\u4e3anltk.tokenize.word_tokenize\u5373\u53ef\u89e3\u51b3\u95ee\u9898\uff1a<\/p>\n<pre>print(nltk.tokenize.word_tokenize(for_test))<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f pycharm\u8c03\u7528nltk\u5305\u65f6\u62a5\u9519 \u5728pycharm\u4e2d\u5b89\u88c5nltk\u5305\u540e\uff0c\u8c03\u7528\u5176\u529f\u80fd\u65f6\u9047\u5230\u4ee5\u4e0b\u62a5\u9519\uff1a attributeerror: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217; \u89e3\u51b3\u6b65\u9aa4 \u6839\u636e\u63d0\u4f9b\u7684\u6587\u6863\uff0cnltk\u7684\u6700\u65b0\u7248\u672c\u5df2\u5f03\u7528word_tokenize\u65b9\u6cd5\uff0c\u5efa\u8bae\u4f7f\u7528nltk.tokenize.word_tokenize\u51fd\u6570\u66ff\u4ee3\u3002\u5c06\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u8c03\u7528\u7684word_tokenize\u65b9\u6cd5\u66ff\u6362\u4e3anltk.tokenize.word_tokenize\u5373\u53ef\u89e3\u51b3\u95ee\u9898\uff1a print(nltk.tokenize.word_tokenize(for_test)) \u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPyCharm \u4e2d\u8c03\u7528 NLTK \u5305\u65f6\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3 `AttributeError: module &#8216;nltk&#8217; has no attribute &#8216;word_tokenize&#8217;`\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-50291","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=50291"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50291\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}