When I was trying to run the below code with python file :
import os
os.environ['USEA-TF'] ='1'
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True)
document = DocumentFile.from_images('IM.jpg')
result = model(document)
result.show(document)
json_response = result.export()
print(json_response)
Getting this error :-
ImportError: cannot import name 'OrderedDict' from 'typing' (c:\users\shubham nagar\appdata\local\programs\python\python37\lib\typing.py)
How will I able to run in .py file
Try as in the code example below
from doctr.io import DocumentFile
from doctr.models import ocr_predictor
import json
model = ocr_predictor(det_arch = 'db_resnet50',
reco_arch = 'crnn_vgg16_bn',
pretrained = True)
Related
Below is the code I am trying to execute and getting import name emd not found. Whereas I have installed pyemd package.
import gensim.downloader as api
import json
from gensim.models.word2vec import Word2Vec
import pyemd
model = Word2Vec.load("final.modelall")
wordlistA = ['data','science']
wordlistB = ['python']
model.wv.wmdistance(wordlistA, wordlistB)
I create a python console app that includes imports of a custom class I'm using. Everytime I run my app I get the error ModuleNotFoundError: "No module named 'DataServices'.
Can you help?
Provided below is my folder structure:
ETL
Baseball
Baseball_DataImport.py
DataServices
DataService.py
ConfigServices.py
PageDataMode.py
SportType.py
Here is the import section from the Baseball_DataImport.py file. This is the file when I run I get the error:
from bs4 import BeautifulSoup
import scrapy
import requests
import BaseballEntity
import mechanize
import re
from time import sleep
import logging
import time
import datetime
from functools import wraps
import json
import DataServices.DataService - Error occurs here
Here is my DataService.py file:
import pymongo
import json
import ConfigServices
import PageDataModel
#from SportType import SportType
class DataServices(object):
AppConfig: object
def __init__(self):
AppConfig = ConfigServices.ConfigService()
#print(AppConfig)
#def GetPagingDataBySport(self,Sport:SportType):
def GetPagingDataBySport(self):
#if Sport == SportType.BASEBALL:
pagingData = []
pagingData.append(PageDataModel.PageDataModel("", 2002, 2))
pagingData.append(PageDataModel.PageDataModel("", 2003, 2))
return pagingData
It might seem that your structure is:
Baseball
Baseball_DataImport.py
Dataservices
Dataservice.py
Maybe you need to do from Dataservices.Dataservice import DataServices
Edit:
I created the folder structure, and the method I showed you works:
Here's the implementation
Dataservice.py only contains:
class DataServices():
pass
Did you try copieing the Dataservice.py into the Projectfolder with the main.py?
I have 2 modules as:
main.py
get.py
In main.py, I need to call a function present in get.py which is call_get().
So I'm trying it this way:
import get
get.call_get()
But it throws an error as 'Attribute Error'.
On the other hand, the following code works:
import temp
temp.func()
function func in temp.py looks as:
import get
get.call_get()
I am unable to understand this behaviour. Please guide.
get.py code:
import requests
import json
import sys
import utils
import error_handler
import get_helper
import os
import pvdata
def call_get():
try:
auth_tuple = utils.get_auth_details("get")
headers = utils.get_header()
resource_types = utils.get_resource_types()
namespaces = utils.get_namespaces()
if resource_types[0].lower() == "all":
resource_types = utils.append_all_resources()
get_helper.get_namespace_list(auth_tuple, headers)
all_namespaces = utils.extract_namespaces_from_list("source")
if namespaces[0].lower() != "all":
error_handler.validate_source_namespaces(namespaces, all_namespaces)
utils.create_file(
"Namespaces", "All_namespaces_at_source.txt", str(all_namespaces))
get_helper.generate_json_for_all_namespaces(
all_namespaces, auth_tuple, headers)
for resource_name in resource_types:
if namespaces[0].lower() == "all":
for namespace in all_namespaces:
get_helper.call_all_functions_for_get(
namespace, resource_name, headers, auth_tuple)
else:
for namespace in namespaces:
get_helper.call_all_functions_for_get(
namespace, resource_name, headers, auth_tuple)
except Exception as error:
filename = os.path.basename(__file__)
error_handler.print_exception_message(error, filename)
return
if __name__ == "__main__":
call_get()
main.py code:
import utils
import remote_exec
import post
import get
import error_handler
import os
import handle_space
import socket
import json
from requests import get
import sys
import temp
def only_dest_requires_jumpserver():
try:
dictionary = {
"migration_type": utils.config_data()["source_cloud"] + " to " + utils.config_data()["dest_cloud"]
}
utils.update_config_file(dictionary)
print("\nInitialising " + utils.config_data()["source_cloud"] + " to " + utils.config_data()["dest_cloud"] + " migration...")
hostname = socket.gethostname()
if hostname == utils.config_data()["my_hostname"]:
# get.call_get()
temp.func()
print("\nData successfully exported from source to this machine.\nChecking for space availability at jumpserver...")
print("Done!")
except Exception as error:
filename = os.path.basename(__file__)
error_handler.print_exception_message(error, filename)
The issue is main.py has 2 get modules as:
import get
from requests import get
get is being overwritten.....you need to rename your function or use
import request
request.get
Another simple way is aliasing suggested by InsertCheesyLine.
from requests import get as _get
and use _get
Code :
from google.cloud import vision
import google.cloud.proto.vision.v1.image_annotator_pb2 as pvv
import io
client = vision.ImageAnnotatorClient()
def mkrl(imageStr):
im_obj = pvv.Image(content = imageStr)
return pvv.AnnotateImageRequest(image = im_obj, features = [{"type": "TEXT_DETECTION"}])
def getR(imageList):
req = map(mkrl,imageList)
response = client.batch_annotate_images(req)
return response
I'm trying to extract text from an image using the google vision api. I need to send a batch of images - things were working fine but now there is this error:
ImportError: No module named 'google.cloud.proto.vision'
this has been solved.....
the correct way to import this is :
import google.cloud.vision_v1.proto.image_annotator_pb2 as pvv
or
from google.cloud.vision_v1.proto import image_annotator_pb2 as pvv
I'm trying to extract features using tsfresh package and extract_features() function.
tsfresh Version: 0.4.0.post0.dev1+ng19fa136
However, I get the following error:
AttributeError: type object 'MinimalFeatureExtractionSettings' has no
attribute 'n_processes'
Code:
import numpy as np
import pandas as pd
column_names = ['time_series1', 'time_series2','time_series3']
ts = np.random.rand(6,3)
df_to_extract = pd.DataFrame(data=ts, columns = column_names)
df_to_extract['id'] = 1
df_to_extract['time'] = np.arange(1,7)
#print(df_to_extract)
import tsfresh
from tsfresh import extract_features
from tsfresh import select_features
from tsfresh.utilities.dataframe_functions import impute
from tsfresh import extract_relevant_features
from tsfresh.feature_extraction import extract_features, MinimalFeatureExtractionSettings
from tsfresh.feature_extraction.settings import *
from tsfresh.feature_extraction.settings import FeatureExtractionSettings
import tsfresh.feature_extraction.settings
from tsfresh import utilities
from tsfresh import feature_extraction
extracted_features = extract_features(df_to_extract,
column_id="id",
column_sort="time",
parallelization= 'per_kind',
feature_extraction_settings= MinimalFeatureExtractionSettings)
Package source code: https://github.com/blue-yonder/tsfresh/blob/master/tsfresh/feature_extraction/extraction.py
I'm using Python 3.5 (Anaconda) on Win10.
I suppose it could be some kind of import error.
How to solve that issue?
Problem solved
To make it work add:
settings= MinimalFeatureExtractionSettings()
extracted_features = extract_features(df_to_extract,
column_id="id",
column_sort="time",
parallelization= 'per_kind',
feature_extraction_settings= settings)
There is no MinimalFeatureExtractionSettings object anymore. It is called MinimalFCParameters now. Thus, you would have to write the following code:
from tsfresh.feature_extraction import extract_features, MinimalFCParameters
...
minimalFCParametersForTsFresh = MinimalFCParameters()
extracted_features = extract_features(df_to_extract,column_id="id",default_fc_parameters = minimalFCParametersForTsFresh)