Gensim: Import KeyedVectors error: cannot import name 'open'

Created on 12 Aug 2019  路  9Comments  路  Source: RaRe-Technologies/gensim

Problem description

I want to import KeyedVectors. Then I got the error: ImportError: cannot import name 'open'

Steps/code/corpus to reproduce

  • Install the latest Gensim version (gensim-3.8.0)
  • Then, try to run 'from gensim.models import KeyedVectors'
  • Afterwards I got an error as printed in the below
    ```Traceback (most recent call last):
    File "fastText_gensim_convert.py", line 3, in
    from gensim.models import KeyedVectors
    File "/usr/local/lib/python3.6/dist-packages/gensim/__init__.py", line 5, in
    from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
    File "/usr/local/lib/python3.6/dist-packages/gensim/parsing/__init__.py", line 4, in
    from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
    File "/usr/local/lib/python3.6/dist-packages/gensim/parsing/preprocessing.py", line 42, in
    from gensim import utils
    File "/usr/local/lib/python3.6/dist-packages/gensim/utils.py", line 45, in
    from smart_open import open
    ImportError: cannot import name 'open'
#### Versions

import platform; print(platform.platform())
Linux-4.15.0-55-generic-x86_64-with-Ubuntu-16.04-xenial
import sys; print("Python", sys.version)
Python 3.6.9 (default, Jul 3 2019, 15:36:16)
[GCC 5.4.0 20160609]
import numpy; print("NumPy", numpy.__version__)
NumPy 1.15.4
import scipy; print("SciPy", scipy.__version__)
SciPy 1.1.0
import gensim; print("gensim", gensim.__version__)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/dist-packages/gensim/__init__.py", line 5, in
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "/usr/local/lib/python3.6/dist-packages/gensim/parsing/__init__.py", line 4, in
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "/usr/local/lib/python3.6/dist-packages/gensim/parsing/preprocessing.py", line 42, in
from gensim import utils
File "/usr/local/lib/python3.6/dist-packages/gensim/utils.py", line 45, in
from smart_open import open
from gensim.models import word2vec;print("FAST_VERSION", word2vec.FAST_VERSION)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/dist-packages/gensim/__init__.py", line 5, in
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "/usr/local/lib/python3.6/dist-packages/gensim/parsing/__init__.py", line 4, in
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "/usr/local/lib/python3.6/dist-packages/gensim/parsing/preprocessing.py", line 42, in
from gensim import utils
File "/usr/local/lib/python3.6/dist-packages/gensim/utils.py", line 45, in
from smart_open import open
ImportError: cannot import name 'open'
```

bug testing

Most helpful comment

you can upgrade smart_open module.
pip3 uninstall smart_open
pip3 install smart_open
and run your code.

All 9 comments

you can upgrade smart_open module.
pip3 uninstall smart_open
pip3 install smart_open
and run your code.

Correct. Duplicate of https://github.com/RaRe-Technologies/smart_open/issues/343.

The fix will be to require the correct version of smart_open in Gensim dependencies. @mpenkov IMO our CI tests should really be running with the oldest supported dependencies. Then issues like this will be caught automatically.

@piskvorky O/, I know @mpenkov has self-assigned the issue to himself but I bumped into the same issue and I think it's annoying.
I don't know how to update the CI tests.
Any hints please? :smile:

@AMR-KELEG I think this was fixed by your PR https://github.com/RaRe-Technologies/gensim/pull/2582 - could you please confirm?

@AMR-KELEG I think this was fixed by your PR #2582 - could you please confirm?

I tried installing gensim from the github develop branch using pip install .
Then executed this command from gensim.models import KeyedVectors and it ran smoothly.
So, yes, the issue is solved.

This issue seems to still be present in the version available via 'conda' (3.8.0). It would be great to have that updated, if that's the issue.

@michaelkarlcoleman The latest version of gensim in conda is 3.8.3. Can you please give that a try?

https://github.com/conda-forge/gensim-feedstock

I have the same issue in gensim 3.8.3 and smart_open 2.0.0

Please open a new issue, with your full details.

Was this page helpful?
0 / 5 - 0 ratings