How to use Custom Python Module in Frappe Framework

For my understanding, to use exture python module, here is what we should do:

  1. pip install what needed within frappe virtual envoirement
  2. import those modules in required py scripts

However, I’ve met some wired problems:

As we can see, the baidu-aip py module has been installed in frappe env.

(frappe) sz@wj16:~/sbang/apps/app_chat/app_chat/api$ pip list
Package            Version
------------------ ---------
baidu-aip          4.16.3

the ‘aip’ module has been imported to py script (btw, the “aip” is module baidu-aip’s name to be used in import.):

import frappe
from frappe import _
from aip import AipSpeech
from urllib.error import URLError

APP_ID = "*****",
API_KEY = "*********",
SECRET_KEY = "*********",

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)


def _get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


@frappe.whitelist(allow_guest=True)
def speech_to_txt(wav):
    try:
        res = client.asr(_get_file_content(wav), 'wav', 16000,
                         {'dev_pid': 1537})
        # print(res)
        txt = ''
        if res['err_no'] == 0:
            txt = res['result'][0]
        return txt
    except URLError as err:
        print('speech_to_txt response http code: ' + str(err.code))

BUT when running the code, it says “app_chat.api.speech.speech_to_txt with No module named ‘aip’”.

I’m very confusing here, why is it? I’ve installed the py module, and the error makes no sense for me.

Need some help here, THANKS!!

to install pip, use:

bench pip install ***