14

I was doing this and got this error :

from gensim.models import Word2Vec

ImportError: cannot import name 'open' from 'smart_open' (C:\ProgramData\Anaconda3\lib\site-packages\smart_open\__init__.py)

Then I did this :

import smart_open
dir(smart_open)

['BZ2File','BytesIO','DEFAULT_ERRORS','IS_PY2','P','PATHLIB_SUPPORT','SSLError','SYSTEM_ENCODING','Uri','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__path__','__spec__','boto','codecs','collections','gzip','hdfs','http','importlib','io','logger','logging','os','pathlib','pathlib_module','requests','s3','s3_iter_bucket','six','smart_open','smart_open_hdfs','smart_open_http','smart_open_lib','smart_open_s3','smart_open_webhdfs','sys','urlparse','urlsplit','warnings','webhdfs']

As you can see there is no 'open' in it so how should I solve this. I tried to install different versions and I upgraded all version too.

Abhishek Prajapat
  • 1,793
  • 2
  • 8
  • 19

7 Answers7

27

I also got the same error. I resolved it by updating the smart_open to version 2.0.0.

conda install smart_open==2.0.0

or

pip install smart_open==2.0.0.

Prasanth Kumar
  • 371
  • 2
  • 4
10
import smart_open
smart_open.open = smart_open.smart_open
from gensim.models import Word2Vec

Works well.

Shooter
  • 330
  • 1
  • 3
  • 8
4

I got the same error, and I solved this error by upgrading the smart_open to the latest version:

conda update smart_open

or

pip install --upgrade smart_open

Po-Yu Kao
  • 2,597
  • 2
  • 12
  • 14
2
\lib\site-packages\gensim\utils.py in <module>
     43 from six.moves import range
     44 
---> 45 from smart_open import open
     46 
     47 from multiprocessing import cpu_count

ImportError: cannot import name 'open'

Same issue for me with smart_open 2.1.0 and gensim 3.8.3. Also after down and upgrading.

Mina L.
  • 163
  • 1
  • 6
1

In C:\ProgramData\Anaconda3\lib\site-packages\gensim\utils.py, I simply changed from smart_open import open to from smart_open import smart_open and it worked.

1

got the same problem.

in gensim/utils.py:

change:

from smart_open import open

to:

from smart_open import open

then replace open with smart_open in the file, reason:

seems that smart_open change the function name from open to smart_open

svyat1s
  • 868
  • 9
  • 12
  • 21
0

Start with

conda update smart_open

if it doesn't work go to gensim/utils.py

and replace

from smart_open import open 

to

from smart_open import open
Sven Eberth
  • 3,057
  • 12
  • 24
  • 29