简体   繁体   中英

ImportError: cannot import name 'Type' when importing 'gensim"

I want to import the "genism" library. I have previously successfully installed it by typing the following in the command prompt:

pip install gensim

However, the following error appears when importing it:

Traceback (most recent call last):
 File "C:/Users/PycharmProjects/untitled/file.py", line 3, in <module>
  import gensim
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\__init__.py", line 5, in <module>
  from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils  # noqa:F401
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\parsing\__init__.py", line 4, in <module>
  from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2,  # noqa:F401
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\parsing\preprocessing.py", line 42, in <module>
  from gensim import utils
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\gensim\utils.py", line 40, in <module>
  import scipy.sparse
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\__init__.py", line 156, in <module>
  from . import fft
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\fft\__init__.py", line 76, in <module>
  from ._basic import (
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\fft\_basic.py", line 1, in <module>
  from scipy._lib.uarray import generate_multimethod, Dispatchable
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\uarray.py", line 27, in <module>
  from ._uarray import *
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\_uarray\__init__.py", line 114, in <module>
  from ._backend import *
 File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\_lib\_uarray\_backend.py", line 1, in <module>
  from typing import (
ImportError: cannot import name 'Type'

I have also previously successfully installed the "typing" library":

pip install typing

What should I do?

It is because Python 3.5 has its own version typing, and it is incompatible with the installed version of gensim. Upgrade to python3.6 could solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM