尝试使用包时的ModuleNotFoundError

时间:2018-01-12 14:43:00

标签: python module importerror

我们有一个在Windows 10上完美运行的自定义模块,但是,它在我们的Linux云实例(Debian Jessie)上因ModuleNotFoundError而失败。 文件夹结构如下:

|-dashboard-miner (git repo)
  |-setup.py
    |-dashboard_miner (the actual package)

我们的setup.py如下:

from setuptools import setup, find_packages
import dashboard_miner
import os

MODULE_BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'dashboard_miner')

try:
    long_description = open('README.md').read()
except IOError:
    long_description = ''

try:
    reqs = open(os.path.join(os.path.dirname(__file__), 'requirements.txt')).read()
except (IOError, OSError):
    reqs = ''

print(find_packages(where=MODULE_BASEDIR))

setup(
    name='dashboard_miner',
    version=dashboard_miner.get_version(short=True),
    description='Data mining utilities for True Cloud Dashboard',
    long_description=long_description,
    url='https://gitlabe1.ext.net.nokia.com/TCI/dashboard-miner',
    author='Hodossy, Szabolcs',
    author_email='szabolcs.hodossy@nokia.com',
    license='NOKIA Confidential',
    packages=find_packages(where=MODULE_BASEDIR),
    package_dir={'': 'dashboard_miner'},
    install_requires=reqs,
    entry_points={
        'console_scripts': [
            'miner=dashboard_miner.cli:main',
        ]
    },
    zip_safe=False
)

2 个答案:

答案 0 :(得分:0)

检查dashboard_miner (the actual package)的文件结构/树,它必须包含 init .py,以便Python可以将其识别为模块。

答案 1 :(得分:0)

实际上,事实证明find_packages函数返回了相对路径,因此必须从正确的文件夹中调用它。