[英]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.