无法从 __init__.py 导入类

问题描述 投票:0回答:0

有一个名为 uszipcode 的模块。安装后模块目录的内容(如果重要):

__init__.py
文件包含:

from ._version import __version__

__short_description__ = (
    "USA zipcode programmable database, includes "
    "2020 census data and geometry information."
)
__license__ = "MIT"
__author__ = "Sanhe Hu"
__author_email__ = "[email protected]"
__maintainer__ = "Sanhe Hu"
__maintainer_email__ = "[email protected]"
__github_username__ = "MacHu-GWU"

try:
    from .search import (
        SearchEngine,
        SimpleZipcode, ComprehensiveZipcode, ZipcodeTypeEnum, SORT_BY_DIST,
    )
except ImportError as e:  # pragma: no cover
    print('hey', e)
except: # pragma: no cover
    raise

当我在脚本中运行此代码时:

from uszipcode import SearchEngine

我明白了

ImportError: cannot import name 'SearchEngine' from 'uszipcode' (d:\Programs\Anaconda\lib\site-packages\uszipcode\__init__.py)

这是什么原因造成的?

python module importerror
© www.soinside.com 2019 - 2024. All rights reserved.