簡體   English   中英

來自本機應用程序分類器的 stderr output:ModuleNotFoundError:沒有名為“nltk”的模塊

[英]stderr output from native app classifier: ModuleNotFoundError: No module named 'nltk'

在嘗試使用 javascript 和 python 之間的本機消息發送/接收數據時,我一直在瀏覽器控制台中遇到以下錯誤 -

來自本機應用程序分類器的 stderr output:ModuleNotFoundError:沒有名為“nltk”的模塊

我已經在我的 pycharm 虛擬環境中安裝了 nltk。 我想在用於本機消息傳遞的 python 文件中使用 nltk 進行一些文本處理。 我沒有收到其他包的任何錯誤消息,例如 sys、json、struct。 但是我收到 nltk 的錯誤消息,keras。但是 pandas 沒有錯誤!!

當我不將 nltk 導入 python 時,本機消息傳遞工作正常。

以下是 python 代碼。 我沒有在這里分享 nltk 部分代碼

import sys
import json
import struct
import nltk


class Informationtransmission:

    def getMessage(self):
        rawLength = sys.stdin.buffer.read(4)
        if len(rawLength) == 0:
            sys.exit(0)
        messageLength = struct.unpack('@I', rawLength)[0]
        message = sys.stdin.buffer.read(messageLength).decode('utf-8')
        return json.loads(message)

    def encodeMessage(self, messageContent):
        encodedContent = json.dumps(messageContent).encode('utf-8')
        encodedLength = struct.pack('@I', len(encodedContent))
        return {'length': encodedLength, 'content': encodedContent}

    def sendMessage(self, encodedMessage):
        sys.stdout.buffer.write(encodedMessage['length'])
        sys.stdout.buffer.write(encodedMessage['content'])
        sys.stdout.buffer.flush()

x = Informationtransmission()
receivedMessage = x.getMessage()

if receivedMessage:
    x.sendMessage(x.encodeMessage(receivedMessage))

js文件

function logTabs(tabs) {
    let tab = tabs[0];

    port.postMessage(tab.url);
}

function listTabs() {
    browser.tabs.query({currentWindow: true, active: true}).then(logTabs, console.error);
}

let port = browser.runtime.connectNative("classifier");

document.addEventListener("click", (e) => {
    if (e.target.id === "url") {
        listTabs();
    }
})

port.onMessage.addListener((response) => {
    console.log("Received: " + response);
});

插件清單.json 文件-

{
    "browser_specific_settings": {
        "gecko": {
            "id": "test@example.org",
          "strict_min_version": "58.0a1"
        }
    },

    "manifest_version": 2,
    "name": "classifier",
    "version": "1.0",

    "description": "Classifies",

    "background": {
        "scripts": ["popup.js"]
    },

    "browser_action":{
        "browser_style": true,
        "default_icon":{
            "48":"/icon.svg"
        },
        "default_title":"classifier",
        "default_popup":"/popup.html"
    },

    "permissions": [
        "tabs",
        "activeTab",
        "scripting",
        "nativeMessaging"
    ]
}

以下是本機應用程序的 bat 和 json 文件-

@echo off

call python -u "E:\proj\send_recieve_info.py"
{
  "name": "classifier",
  "description": "host for native messaging",
  "path": "E:\\proj\\calltoscript.bat",
  "type": "stdio",
  "allowed_extensions": ["test@example.org"]
}

其實我明白了。 python 指向的路徑沒有 nltk 和 keras。插件使用的是來自系統路徑的 python,而不是我想的來自虛擬環境。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM