ModuleNotFoundError when pip installing package, but not when using python setup.py install

时间:2019-04-16 22:49:29

标签: python pip packaging

I've restructured a project to the src directory structure. It looks like this:

root_dir/
    src/
        module1/
            __init__.py
            script1.py
            script2.py
        module2/
            __init__.py
            other_script1.py
            other_script2.py
    conftest.py
    setup.py
    tests/
        conftest.py
        some_tests/
            conftest.py
            test_some_parts.py
        some_other_tests/
            conftest.py
            test_these_other_parts.py

My setup.py looks like this:

setup(
    name='Project',
    version=0.0,
    author='Me',
    install_requires=['pyodbc'],
    tests_require=['pytest'],
    setup_requires=['pytest-runner'],
    test_suite='root_dir.Tests',
    entry_points={
     'console_scripts': ['load_data = module1.script1:main']
    },
    package_data={'Config': ['*.json']},
    packages=find_packages('src'),
    package_dir={'': 'src'})

I am running Anaconda3 on Windows 10. When I run python setup.py install, I am able to run the load_data script without any issue. However, from what I've been reading, it is preferable to use pip install . vice python setup.py install. When I pip install the package and attempt to run load_data, I get ModuleNotFoundError: No module named 'module1.script1'. I've attempted adding 'src' to the front of this, but this doesn't work either. I don't understand what the differences are or how to troubleshoot this.

1 个答案:

答案 0 :(得分:0)

When building the source distribution for the package not all files are included。尝试使用创建一个MANIFEST.in文件

recursive-include src/module1 *