Repository: piskvorky/gensim

Issue:
Import KeyedVectors error: cannot import name 'open'
<!--
**IMPORTANT**:

- Use the [Gensim mailing list](https://groups.google.com/forum/#!forum/gensim) to ask general or usage questions. Github issues are only for bug reports.
- Check [Recipes&FAQ](https://github.com/RaRe-Technologies/gensim/wiki/Recipes-&-FAQ) first for common answers.

Github bug reports that do not include relevant information and context will be closed without an answer. Thanks!
-->

#### 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 <module>
    from gensim.models import KeyedVectors
  File "/usr/local/lib/python3.6/dist-packages/gensim/__init__.py", line 5, in <module>
    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 <module>
    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 <module>
    from gensim import utils
  File "/usr/local/lib/python3.6/dist-packages/gensim/utils.py", line 45, in <module>
    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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/gensim/__init__.py", line 5, in <module>
    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 <module>
    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 <module>
    from gensim import utils
  File "/usr/local/lib/python3.6/dist-packages/gensim/utils.py", line 45, in <module>
    from smart_open import open
>>> from gensim.models import word2vec;print("FAST_VERSION", word2vec.FAST_VERSION)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/gensim/__init__.py", line 5, in <module>
    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 <module>
    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 <module>
    from gensim import utils
  File "/usr/local/lib/python3.6/dist-packages/gensim/utils.py", line 45, in <module>
    from smart_open import open
ImportError: cannot import name 'open'
```





Discussion:
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.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -381,7 +381,7 @@ def finalize_options(self):
         NUMPY_STR,
         'scipy >= 0.18.1',
         'six >= 1.5.0',
-        'smart_open >= 1.7.0',
+        'smart_open >= 1.8.1',
     ],
     tests_require=linux_testenv,
     extras_require={


Test patch: