Windows正常运行的自定义Python模块在Debian Linux触发ModuleNotFoundError
Fixing ModuleNotFoundError for Custom Python Module on Debian Jessie
Let's break down why your module works smoothly on Windows 10 but throws a ModuleNotFoundError on Debian Jessie, and walk through how to fix it.
Root Cause Analysis
Looking at your setup.py and directory structure, the core issue lies in misconfigured package detection settings:
- Your
dashboard_minerpackage lives directly in the repo root (right next tosetup.py), but your current setup tells setuptools to search for packages inside thedashboard_minerdirectory viafind_packages(where=MODULE_BASEDIR), and maps the root package to that same directory withpackage_dir={'': 'dashboard_miner'}. - This means setuptools is only looking for sub-packages (like
dashboard_miner.utils) insidedashboard_miner, not the maindashboard_minerpackage itself. Windows might have been falling back to the local directory during testing, hiding this flaw—but on Debian, the installed package is missing the core module entirely.
If you run your current setup.py on Debian, the print(find_packages(where=MODULE_BASEDIR)) line will likely output an empty list, confirming no packages are being detected for installation.
Step-by-Step Fix
Here's the adjusted setup.py that correctly packages your module for both systems:
from setuptools import setup, find_packages import os import sys # Add the repo root to sys.path to ensure dashboard_miner is importable during setup sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import dashboard_miner try: with open('README.md', 'r') as f: long_description = f.read() except IOError: long_description = '' try: with open(os.path.join(os.path.dirname(__file__), 'requirements.txt'), 'r') as f: # Clean up requirements (ignore comments and empty lines) reqs = [line.strip() for line in f if line.strip() and not line.startswith('#')] except (IOError, OSError): reqs = [] # Verify package detection (should output ['dashboard_miner']) print(find_packages()) 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(), # Automatically detects the dashboard_miner package in the repo root install_requires=reqs, entry_points={ 'console_scripts': [ 'miner=dashboard_miner.cli:main', ] }, zip_safe=False )
Post-Fix Verification
- Double-check that your
dashboard_minerdirectory has an__init__.pyfile (even an empty one)—Python requires this to recognize it as a valid package. - On Debian, install the package with
pip install .(usepip install -e .for editable development mode) after applying the changes. - Confirm the module works by running
python -c "import dashboard_miner"—no errors mean the fix worked.
内容的提问来源于stack exchange,提问作者user9209366
相关产品推荐
相关产品推荐

