Синтаксическая ошибка при импорте nltk при запуске с сервером wsgi - PullRequest
1 голос
/ 28 апреля 2020

Я хотел разместить свой проект python chatbot на экземпляре EC2, и я установил все пакеты, и он работает локально, но когда я пытаюсь запустить его на сервере wsgi, я получаю следующую ошибку. Я попытался переустановить nltk, и это также не будет работать, я не могу понять, в чем проблема, и я пытаюсь запустить этот apache 2 wsgi сервер

Exception occurred processing WSGI script '/var/www/html/serving_static/app.wsgi'., referer: 15.206.169.14/serving_static

Traceback (most recent call last):, referer: 'http://15.206.169.14/serving_static'

 File "/var/www/html/serving_static/app.wsgi", line 12, in <module>, referer: 
15.206.169.14/serving_static
  from app import app as application, referer: http://15.206.169.14/serving_static

 File "/var/www/html/serving_static/app.py", line 3, in <module>, referer: 
15.206.169.14/serving_static
   import chatgui, referer: http://15.206.169.14/serving_static

 File "/var/www/html/serving_static/chatgui.py", line 1, in <module>, referer: 
15.206.169.14/serving_static
   import nltk, referer: http://15.206.169.14/serving_static

 File "/home/ubuntu/serving_static/env/lib/python3.8/site-packages/nltk/__init__.py", line 128, in <module>, referer: http://15.206.169.14/serving_static
   from nltk.collocations import *, referer: 15.206.169.14/serving_static

 File "/home/ubuntu/serving_static/env/lib/python3.8/site-packages/nltk/collocations.py", line 35, in <module>, referer: http://15.206.169.14/serving_static
   from nltk.probability import FreqDist, referer: 15.206.169.14/serving_static

 File "/home/ubuntu/serving_static/env/lib/python3.8/site-packages/nltk/probability.py", line 333, referer: http://15.206.169.14/serving_static
   print("%*s" % (width, samples[i]), end=" "), referer: 15.206.169.14/serving_static
                                         ^, referer: 15.206.169.14/serving_static

SyntaxError: invalid syntax, referer: http://15.206.169.14/serving_static

Я хотел знать, как исправить что.

Python код:

from flask import Flask, request, jsonify, make_response
from flask import render_template
import chatgui
import train_chatbot
import keras.backend.tensorflow_backend as tb

tb._SYMBOLIC_SCOPE.value = True
from pymongo import MongoClient


def create_db():
    client = MongoClient()

    if "ggbot" in client.list_database_names():
        pass
    else:
        test = client["ggbot"]

    mydb = client.ggbot

    if "check" in mydb.list_collection_names():
        pass
    else:
        test = mydb["check"]

    mycol = mydb["check"]
    train_check = {"train_run": 1}
    mycol.insert_one(train_check)


def check_train():
    client = MongoClient()
    if "ggbot" not in client.list_database_names():
        create_db()
    else:
        mydb = client["ggbot"]
        mycol = mydb["check"]
        x = mycol.find_one({"train_run": 1})
        x = x["train_run"]
        if x == 1:
            pass
        else:
            train_chatbot.train_model()


check_train()

app = Flask(__name__)


@app.route("/", methods=['GET', 'POST'])
def next_web():
    answers = ""
    if request.method == 'POST':
        req = request.get_json(force=True)
        answers = req["answer"]

    f = open("abc.txt", "w")
    f.write(answers)
    f.close()

    data = chatgui.chatbot_response()

    return render_template("index.html", data=data)


# run the application
if __name__ == "__main__":
    app.run(debug=False)

WSGI.py:

activate_this = '/home/ubuntu/serving_static/env/bin/activate_this.py'
with open(activate_this) as f:
        exec(f.read(), dict(__file__=activate_this))

import sys
import logging

logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/serving_static/")

from app import app as application

Спасибо за помощь

...