简体   繁体   English

pip 安装包时出现 ModuleNotFoundError,但在使用 python setup.py install 时却没有

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

I've restructured a project to the src directory structure.我已经将项目重组为src目录结构。 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.py看起来像这样:

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.我在 Windows 10 上运行 Anaconda3。当我运行python setup.py install时,我能够毫无问题地运行load_data脚本。 However, from what I've been reading, it is preferable to use pip install.但是,根据我一直在阅读的内容,最好使用pip install. vice python setup.py install .python setup.py install When I pip install the package and attempt to run load_data , I get ModuleNotFoundError: No module named 'module1.script1' .当我 pip 安装包并尝试运行load_data时,我得到ModuleNotFoundError: No module named 'module1.script1' I've attempted adding 'src' to the front of this, but this doesn't work either.我尝试在前面添加'src' ,但这也不起作用。 I don't understand what the differences are or how to troubleshoot this.我不明白有什么区别或如何解决这个问题。

When building the source distribution for the package not all files are included .在为包构建源代码分发时,并非所有文件都包含在内 Try creating a MANIFEST.in file with尝试创建一个MANIFEST.in文件

recursive-include src/module1 *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 package 的 setup.py 安装版本时出现 ModuleNotFoundError,但不是本地 - - ModuleNotFoundError when using setup.py install version of package, but not locally- 使用setup.py安装软件包时不会创建Pyenv填充程序 - Pyenv shim not created when installing package using setup.py 可以指定使用pip和distutils setup.py时要安装python软件包的工件吗? - Possible to specify artifactory to install python packages from when using pip and distutils setup.py? 无法使用 PIP 和 setup.py 安装 Python 密码学 package - Failed to install Python Cryptography package with PIP and setup.py PIP安装没有setup.py文件的Python包? - PIP install a Python Package without a setup.py file? Python 3.7.3 Setup.py Package 中的 ModuleNotFoundError - ModuleNotFoundError in Python 3.7.3 Setup.py Package 安装 Python package: setup.py install - error: no commands supplied - Installing Python package: setup.py install - error: no commands supplied 使用 setup.py 从 pip 安装后 ModuleNotFoundError - ModuleNotFoundError after installing from pip with setup.py 在开发时,为什么`pip install .`要比`python setup.py install`慢得多? - When developing, why is `pip install .` so much slower than `python setup.py install`? 通过pip安装时,获取命令“ python setup.py egg_info”失败,错误代码为1 - Getting Command “python setup.py egg_info” failed with error code 1 when installing via pip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM