Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import KeyedVectors error: cannot import name 'open' #2576

Closed
GlorianY opened this issue Aug 12, 2019 · 9 comments · Fixed by #2582
Closed

Import KeyedVectors error: cannot import name 'open' #2576

GlorianY opened this issue Aug 12, 2019 · 9 comments · Fixed by #2582
Assignees
Labels
bug Issue described a bug testing Issue related with testing (code, documentation, etc)

Comments

@GlorianY
Copy link

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
  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'
@ChandlerGrowing
Copy link

ChandlerGrowing commented Aug 13, 2019

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

@piskvorky
Copy link
Owner

piskvorky commented Aug 13, 2019

Correct. Duplicate of piskvorky/smart_open#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 piskvorky added bug Issue described a bug testing Issue related with testing (code, documentation, etc) labels Aug 13, 2019
@mpenkov mpenkov self-assigned this Aug 14, 2019
@AMR-KELEG
Copy link
Contributor

AMR-KELEG commented Aug 21, 2019

@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? 😄

@mpenkov
Copy link
Collaborator

mpenkov commented Aug 26, 2019

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

@AMR-KELEG
Copy link
Contributor

@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.

@michaelkarlcoleman
Copy link

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.

@mpenkov
Copy link
Collaborator

mpenkov commented May 21, 2020

@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

@NoaLe5
Copy link

NoaLe5 commented May 28, 2020

I have the same issue in gensim 3.8.3 and smart_open 2.0.0

@piskvorky
Copy link
Owner

piskvorky commented May 28, 2020

Please open a new issue, with your full details.

Repository owner locked as resolved and limited conversation to collaborators May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue described a bug testing Issue related with testing (code, documentation, etc)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants