I have model trained on colab and now I want to use that in my centOS7-server like this
import json
from flask import Flask, jsonify, request
import mysql.connector as mariadb
from simpletransformers.ner import NERModel,NERArgs
model = NERModel('bert', './checkpoint-14000', use_cuda= False)
model_args = NERArgs()
model_args.lazy_loading = True
app = Flask(__name__)
#app.route('/sp', methods=['POST'])
def addOne():
try:
prediction = model.predict([json.loads(request.data)['txt']])
return jsonify({'OK': prediction[0][0]})
except Exception as e:
return jsonify({'ERROR': e})
if __name__ == '__main__':
app.run(host='0.0.0.0')
I use python3.9
but I got the ERROR
Traceback (most recent call last):
File "/home/milad/flask/./wsgi.py", line 1, in <module>
from myproject import app
File "/home/milad/flask/./myproject.py", line 4, in <module>
from simpletransformers.ner import NERModel,NERArgs
File "/usr/local/lib/python3.9/site-packages/simpletransformers/ner/__init__.py", line 2, in <module>
from simpletransformers.ner.ner_model import NERModel
File "/usr/local/lib/python3.9/site-packages/simpletransformers/ner/ner_model.py", line 24, in <module>
from simpletransformers.ner.ner_utils import (
File "/usr/local/lib/python3.9/site-packages/simpletransformers/ner/ner_utils.py", line 33, in <module>
from datasets import load_dataset
File "/usr/local/lib/python3.9/site-packages/datasets/__init__.py", line 37, in <module>
from .arrow_dataset import Dataset, concatenate_datasets
File "/usr/local/lib/python3.9/site-packages/datasets/arrow_dataset.py", line 62, in <module>
from .arrow_reader import ArrowReader
File "/usr/local/lib/python3.9/site-packages/datasets/arrow_reader.py", line 29, in <module>
from .download.download_config import DownloadConfig
File "/usr/local/lib/python3.9/site-packages/datasets/download/__init__.py", line 9, in <module>
from .download_manager import DownloadManager, DownloadMode
File "/usr/local/lib/python3.9/site-packages/datasets/download/download_manager.py", line 29, in <module>
from ..utils.file_utils import cached_path, get_from_cache, hash_url_to_filename, is_relative_path, url_or_path_join
File "/usr/local/lib/python3.9/site-packages/datasets/utils/file_utils.py", line 30, in <module>
from .extract import ExtractManager
File "/usr/local/lib/python3.9/site-packages/datasets/utils/extract.py", line 3, in <module>
import lzma
File "/usr/local/lib/python3.9/lzma.py", line 27, in <module>
from _lzma import *
ModuleNotFoundError: No module named '_lzma'
I find my answer in this just look at the Solution
Related
All of a sudden i am getting below error while running my code in Pycharm. Earlier It was working fine. I tried changing the interpretar from virtual en to base interpreter but no resolve
Traceback (most recent call last):
File "/Users/ubhatia/PycharmProjects/ModerationReport/resources/user_keywords/keyword.py", line 3, in <module>
from robot.api.deco import library, keyword
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/__init__.py", line 43, in <module>
from robot.rebot import rebot, rebot_cli
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/rebot.py", line 40, in <module>
from robot.conf import RebotSettings
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/conf/__init__.py", line 27, in <module>
from .settings import RobotSettings, RebotSettings
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/conf/settings.py", line 16, in <module>
import glob
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/glob.py", line 4, in <module>
import re
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 127, in <module>
import functools
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py", line 21, in <module>
from collections import namedtuple
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 22, in <module>
from keyword import iskeyword as _iskeyword
File "/Users/ubhatia/PycharmProjects/ModerationReport/resources/user_keywords/keyword.py", line 3, in <module>
from robot.api.deco import library, keyword
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/api/__init__.py", line 71, in <module>
from robot.model import SuiteVisitor
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/model/__init__.py", line 28, in <module>
from .body import BaseBody, Body, BodyItem, Branches
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/model/body.py", line 18, in <module>
from .itemlist import ItemList
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/model/itemlist.py", line 17, in <module>
from functools import total_ordering
ImportError: cannot import name 'total_ordering' from 'functools' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py)
This is the piece of code i am running
import time
from datetime import date, timedelta
from robot.api.deco import library, keyword
from robot.libraries.BuiltIn import BuiltIn
import pandas as pd
def get_current_date():
today = time.strftime('%d/%m/%Y')
return today
def get_yesterday_date():
today = date.today()
yesterday = today - timedelta(days=1)
return yesterday.strftime('%d/%m/%Y')
def read_excel_and_change_to_list(excel_path):
return pd.read_excel(excel_path)
print(get_current_date())
Can anyone help me out on how to resolve this issue please?
I use python3.6.0 (googletrans3.0). I import googletrans3.0.
Traceback (most recent call last):
File "C:\Python\Python36-32\traduction essai.py", line 3, in <module>
import googletrans
File "C:\Python\Python36-32\lib\site-packages\googletrans\__init__.py", line 6, in <module>
from googletrans.client import Translator
File "C:\Python\Python36-32\lib\site-packages\googletrans\client.py", line 10, in <module>
import httpcore
File "C:\Python\Python36-32\lib\site-packages\httpcore\__init__.py", line 2, in <module>
from ._async.connection_pool import AsyncConnectionPool
File "C:\Python\Python36-32\lib\site-packages\httpcore\_async\connection_pool.py", line 4, in <module>
from .._backends.auto import AsyncLock, AsyncSemaphore, AutoBackend
File "C:\Python\Python36-32\lib\site-packages\httpcore\_backends\auto.py", line 4, in <module>
import sniffio
File "C:\Python\Python36-32\lib\site-packages\sniffio\__init__.py", line 10, in <module>
from ._impl import (
File "C:\Python\Python36-32\lib\site-packages\sniffio\_impl.py", line 1, in <module>
from contextvars import ContextVar
File "C:\Python\Python36-32\lib\site-packages\contextvars\__init__.py", line 4, in <module>
import immutables
File "C:\Python\Python36-32\lib\site-packages\immutables\__init__.py", line 18, in <module>
from ._protocols import MapKeys as MapKeys
File "C:\Python\Python36-32\lib\site-packages\immutables\_protocols.py", line 6, in <module>
from typing import NoReturn
ImportError: cannot import name 'NoReturn'
image
This is my code:
from example1 import db, Puppy
db.create_all()
sam = Puppy('Sammy', 3)
frank = Puppy ('Frankie',2)
print (sam.id)
print (frank.id)
db.session.add_all([sam,frank])
db.session.commit()
print(sam.id)
print(frank.id)
And this is my error:
& C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
PS R:\dinabelajar\Flask-Bootcamp-master> & C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
PS R:\dinabelajar\Flask-Bootcamp-master> & C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
PS R:\dinabelajar\Flask-Bootcamp-master> & C:/Python/Python38/python.exe r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py
Traceback (most recent call last):
File "r:/dinabelajar/Flask-Bootcamp-master/05-Databases/coba/setdatabase.py", line 1, in <module>
from example1 import db, Puppy
File "r:\dinabelajar\Flask-Bootcamp-master\05-Databases\coba\example1.py", line 3, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 22, in <module>
import sqlalchemy
File "C:\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 172, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
How can i fix this?
you must update SQLAlchemy
pip uninstall SQLAlchemy
pip install SQLAlchemy==1.3.6
change time.clock() to time.perf_counter() in python 3.8
I am getting syntax error when i try to run my py file.
Traceback (most recent call last):
File "/home/ubuntu/environment/run.py", line 2, in <module>
from flask import Flask
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
File "/home/ubuntu/.local/lib/python3.6/site-packages/jinja2/__init__.py", line 82, in <module>
_patch_async()
File "/home/ubuntu/.local/lib/python3.6/site-packages/jinja2/__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "/home/ubuntu/.local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 13, in <module>
import asyncio
File "/usr/lib/python3.6/asyncio/__init__.py", line 21, in <module>
from .base_events import *
File "/usr/lib/python3.6/asyncio/base_events.py", line 17, in <module>
import concurrent.futures
File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/_base.py", line 414
raise exception_type, self._exception, self._traceback
^
SyntaxError: invalid syntax
The code causing this problem is as follows:
import os
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello():
return "Hello World"
if __name__ == '__main__':
app.run(host=os.environ.get('IP'),
port=int(os.environ.get('PORT')),
debug=True)
Plenty of these threads but I'm still mega confused. I'm getting a ImportError and I can't figure out what I'm doing wrong...
Heres the error message:
File "/app/src/pptxbuilder/app.py", line 85, in <module>
__web_setup()
File "/app/src/pptxbuilder/app.py", line 35, in __web_setup
from pptxbuilder.views.home import home_bp
File "/app/src/pptxbuilder/views/__init__.py", line 2, in <module>
from .builder import builder_bp
File "/app/src/pptxbuilder/views/builder.py", line 30, in <module>
from pptxbuilder.app import app
File "/app/src/pptxbuilder/app.py", line 85, in <module>
__web_setup()
File "/app/src/pptxbuilder/app.py", line 36, in __web_setup
from pptxbuilder.views.builder import builder_bp
ImportError: cannot import name 'builder_bp'
Here are my paths:
src\pptxbuilder\app.py
src\pptxbuilder\views\builder.py
src\pptxbuilder\views\home.py
In 'builder.py' I have this variable
builder_bp = Blueprint('builder', __name__)
In 'home.py' I have this variable
home_bp = Blueprint('home', __name__)
And I'm running the line below in 'app.py'
'from pptxbuilder.views.builder import builder_bp'
Remove pptxbuilder.
from views.builder import builder_bp
Simple example, but the concept should be the same. Your exact code will be different of course.