Forums

No Module Named apiai

I am getting the following error: ModuleNotFoundError: No module named 'apiai'

But it is in my Python3.5 Site-Packages directory and if I bash anywhere else to install it says its already installed.

I originally used the following command to install: pip3.5 install --user apiai

Did I do something wrong??

Error saying its at line 2... Here is my code:

import json
import apiai
from flask import Flask
import twilio.twiml
from twilio.rest import TwilioRestClient

# Twilio account info
account_sid = "my account sid"
auth_token = "my token code"
account_num = "my phone number"
client = TwilioRestClient(account_sid, auth_token)

# api.ai account info
CLIENT_ACCESS_TOKEN = "my access token"
ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN)

app = Flask(__name__)

@app.route('/hello')
def hello_world():
return 'Hello api.ai (from Flask!)'

@app.route("/", methods=['GET', 'POST'])
def server():
from flask import request
# get SMS input via twilio
resp = twilio.twiml.Response()

# get SMS metadata
msg_from = request.values.get("From", None)
msg = request.values.get("Body", None)

# prepare API.ai request
req = ai.text_request()
req.lang = 'en'  # optional, default value equal 'en'
req.query = msg

# get response from API.ai
api_response = req.getresponse()
responsestr = api_response.read().decode('utf-8')
response_obj = json.loads(responsestr)
if 'result' in response_obj:
    response = response_obj["result"]["fulfillment"]["speech"]
    # send SMS response back via twilio
    client.messages.create(to=msg_from, from_= account_num, body=response)

return str(resp)

if __name__ == "__main__":app.run(debug=True)

check the following:

  • your webapp settings uses python 3.5
  • if using virtualenv ensure that module is installed there (workon and pip) and wepabb settings point to the virtualenv

If you're definitely on Python 3.5, have you reloaded the website using the button on the "Web" page after installing apiai?