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)
Related
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)
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 am trying to use a keras application in pycharm. I start my script off with the following imports:
from keras_vggface.vggface import VGGFace
from keras_vggface.utils import preprocess_input
from keras_vggface.utils import decode_predictions
Upon running this block of code, I get this error:
ImportError: You need to first `import keras` in order to use `keras_applications`. For instance, you can do:
```
import keras
from keras_applications import vgg16
```
Or, preferably, this equivalent formulation:
```
from keras import applications
```
I have tried importing the appropriate keras libraries as suggested, but the problem persists. I have also tried checking the json file to see if it contains the correct backend(it does).
How can I resolve this issue?
"edit for clarity"
My full imports go as follows:
from PIL import Image # for extracting image
from numpy import asarray
from numpy import expand_dims
from matplotlib import pyplot
from mtcnn.mtcnn import MTCNN # because i am too lazy to make one myself
import keras
from keras_applications import vgg16
from keras_vggface.vggface import VGGFace
from keras_vggface.utils import preprocess_input
from keras_vggface.utils import decode_predictions
Traceback:
Traceback (most recent call last):
File "C:/Users/###/PycharmProjects/##/#.py", line 17, in <module>
from keras_applications import vgg16
File "C:\Users\###\anaconda3\envs\tensor\lib\site-packages\keras_applications\vgg16.py", line 17, in <module>
backend = get_keras_submodule('backend')
File "C:\Users\###\anaconda3\envs\tensor\lib\site-packages\keras_applications\__init__.py", line 39, in get_keras_submodule
raise ImportError('You need to first `import keras` '
ImportError: You need to first `import keras` in order to use `keras_applications`. For instance, you can do:
```
import keras
from keras_applications import vgg16
```
Or, preferably, this equivalent formulation:
```
from keras import applications
```
Process finished with exit code 1
Are you planning to use the Tensorflow framework for executing the model. If it is tensorflow then i suggest using
import tensorflow as tf \ from tensorflow.keras.applications.vgg16 import VGG. Keras comes in-built in latest TF framework and hence we dont have to do an explicit import
even otherwise if you want to use Keras directly i believe the code should be :
import keras \ from keras.applications.vgg16 import VGG16 \ vggmodel = VGG16(weights='imagenet', include_top=True)
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)
I've written a python file and am trying to import it but it's not recognized.
The file was saved as gentleboost_c_class.c in C:\User\apps\My documents.
I tried to import it like this:
import gentleboost_c_class as gbc
But I get this error:
NameError: name 'gentleboost_c_class' is not defined
gentleboost_c_class.py begins like this:
from sklearn.externals.six.moves import zip
import numpy as np
import statsmodels.api as sm
class GentleBoostC:
.....
It compiles fine.
Both files are in the same folder.
What am I doing wrong?
You're getting a NameError, not an ImportError.
So it seems to me that you import your module as gbc, but later try to refer to it as gentleboost_c_class.
If you import the module with
import gentleboost_c_class as gbc
that means it will be available under the global name gbc, but not as gentleboost_c_class.