Python 3.7.7 ImportError: cannot import name 'LSHash' from 'lshash'

Python 3.7.7 ImportError: cannot import name 'LSHash' from 'lshash'

我正在使用 Python 3.7.7。我有一个 class 定义为

class LSHash(object):
  def __init__(self, hash_size, input_dim, num_hashtables=1,
             storage_config=None, matrices_filename=None, overwrite=False):
  #...

当我尝试使用

lshash 模块导入 Python class LSHash
from lshash import LSHash

我有一个 ImportError:

Traceback (most recent call last):
  File "example.py", line 3, in <module>
    from lshash import LSHash
ImportError: cannot import name 'LSHash' from 'lshash' (/Users/loretoparisi/Documents/MyProjects/lshash/lshash/__init__.py)

未来的lshash.py进口:

from __future__ import print_function, unicode_literals, division, absolute_import
from builtins import int, round, str,  object  # noqa
from future import standard_library
standard_library.install_aliases()  # noqa: Counter, OrderedDict, 
from past.builtins import basestring   # noqa:

import future        # noqa
import builtins      # noqa
import past          # noqa
import six           # noqa

重现错误的代码是 here

您可以在 __init__.py 文件中进行相对导入,如下所示:

from .lshash import *
from .storage import *

Intra-package References

Good example