如何解决在setuptools中将目录模块添加到py_modules中
我可能又犯了一个愚蠢的错误。但是我找不到它。即使在这个极小的最小(不是)工作示例中……
文件夹结构:
setup.py
x_module
__init__.py
main.py
setup.py
包含
from setuptools import setup
setup(
name= 'setup-test',version='0.1',py_modules = ['x_module' ],entry_points = '''
[console_scripts]
x_test=x_module.main:main
'''
)
__init__.py
为空
main.py
包含
#!/usr/bin/env python3
def main():
print('x_module.main.main() executed')
命令行输出:
$ pip install .
Processing /workspaces/setup_py_test
Building wheels for collected packages: setup-test
Building wheel for setup-test (setup.py) ... done
Created wheel for setup-test: filename=setup_test-0.1-py3-none-any.whl size=1263 sha256=52c02b70254467e4d10955dc520b692a320f93c858e77711f77b0ab286f422d5
Stored in directory: /tmp/pip-ephem-wheel-cache-miymlm3k/wheels/a1/08/94/6f5e7ee293420487584919e807df93ea4d84adc23ab40faf00
Successfully built setup-test
Installing collected packages: setup-test
Attempting uninstall: setup-test
Found existing installation: setup-test 0.1
Uninstalling setup-test-0.1:
Successfully uninstalled setup-test-0.1
Successfully installed setup-test-0.1
$ x_test
Traceback (most recent call last):
File "/usr/local/bin/x_test",line 5,in <module>
from x_module.main import main
ModuleNotFoundError: No module named 'x_module'
奇怪的是它在可编辑模式下工作:
$ pip install -e .
Obtaining file:///workspaces/setup_py_test
Installing collected packages: setup-test
Attempting uninstall: setup-test
Found existing installation: setup-test 0.1
Uninstalling setup-test-0.1:
Successfully uninstalled setup-test-0.1
Running setup.py develop for setup-test
Successfully installed setup-test
$ x_test
x_module.main.main() executed
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。