baskarmac
baskarmac

Reputation: 35

Importing Gensim gensim.models.phrases import phraser fails with "ImportError: cannot import name 'Type'"

I am using Python version 3.5 in a virtual environment and when trying to import the below command i am getting "ImportError: cannot import name 'Type'"

from gensim.models.phrases import Phraser

I have uninstalled all other packages and just installed gensim and still it fails. Any suggestions would be of great help

----> 1 from gensim.models.phrases import Phraser 2 from gensim.models.word2vec import Word2Vec 3 import pickle 4 from botocore.client import Config

/simcloud-packages/venv/lib/python3.5/site-packages/gensim/init.py in 3 """ 4 ----> 5 from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401 6 import logging 7

/simcloud-packages/venv/lib/python3.5/site-packages/gensim/parsing/init.py in 2 3 from .porter import PorterStemmer # noqa:F401 ----> 4 from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401 5 strip_tags, strip_short, strip_numeric, 6 strip_non_alphanum, strip_multiple_whitespaces,

/simcloud-packages/venv/lib/python3.5/site-packages/gensim/parsing/preprocessing.py in 40 import glob 41 ---> 42 from gensim import utils 43 from gensim.parsing.porter import PorterStemmer 44

/simcloud-packages/venv/lib/python3.5/site-packages/gensim/utils.py in 38 import numpy as np 39 import numbers ---> 40 import scipy.sparse 41 42 from six import iterkeys, iteritems, itervalues, u, string_types, unichr

/simcloud-packages/venv/lib/python3.5/site-packages/scipy/init.py in 154 # This makes "from scipy import fft" return scipy.fft, not np.fft 155 del fft --> 156 from . import fft

/simcloud-packages/venv/lib/python3.5/site-packages/scipy/fft/init.py in 74 from future import division, print_function, absolute_import 75 ---> 76 from ._basic import ( 77 fft, ifft, fft2, ifft2, fftn, ifftn, 78 rfft, irfft, rfft2, irfft2, rfftn, irfftn,

/simcloud-packages/venv/lib/python3.5/site-packages/scipy/fft/_basic.py in ----> 1 from scipy._lib.uarray import generate_multimethod, Dispatchable 2 import numpy as np 3 4 5 def _x_replacer(args, kwargs, dispatchables):

/simcloud-packages/venv/lib/python3.5/site-packages/scipy/_lib/uarray.py in 25 from uarray import _Function 26 else: ---> 27 from ._uarray import * 28 from ._uarray import _Function 29

/simcloud-packages/venv/lib/python3.5/site-packages/scipy/_lib/_uarray/init.py in 112 """ 113 --> 114 from ._backend import * 115 116 version = '0.5.1+5.ga864a57.scipy'

/simcloud-packages/venv/lib/python3.5/site-packages/scipy/_lib/_uarray/_backend.py in ----> 1 from typing import ( 2 Callable, 3 Iterable,enter code here 4 Dict, 5 Tuple,

ImportError: cannot import name 'Type'

Upvotes: 0

Views: 1577

Answers (1)

gojomo
gojomo

Reputation: 54213

While you've triggered this error via from gensim.models.phrases import Phraser, the error stack indicates the line of code triggering the error is deep within the scipy package.

Specifically, it seems like gensim's attempt to merely import scipy.sparse is what leads to the error. So, it'd be useful to check if you can also trigger the error with import scipy.sparse – and if so, you have a recipe for the error that doesn't involve gensim at all, and might be worth asking as a scipy question (here on StackOverflow or in some scipy forum).

You should check what scipy and numpy versions are installed in your environment, and whether they still support Python 3.5. As Python 3.5 is barely 6 months away from its "end-of-life", when not even urgent security issues will receive fixes, you may wish to try a later Python, which might also resolve this issue. (I believe there have been a number of changes around Type-related features after Python 3.5.)

Upvotes: 0

Related Questions