我正在开发一个Python包,我想在其中添加一些示例。
我的目标是能够通过执行以下操作来执行它们:
python3 -m package.examples.example_file_1
example1将被执行
但是,我不知道该怎么做。 这是我的文件结构:
Package
|─ examples
| |─ __init__.py
| |─ example_file_1.py
| |─ example_file_2.py
| |─ example_file_3.py
|─ __init__.py
|─ package_file_1.py
|─ package_file_2.py
|─ package_file_3.py
|─ package_file_4.py
当我运行python3 -m package.examples.example_file_1
命令时,我得到了:
/usr/bin/python3.8: Error while finding module specification for 'package.examples.example_file_1' (ModuleNotFoundError: No module named 'package.examples')
解决方案:在我的setup.py文件中,我使用的是setuptools.find_packages()
而不是setuptools.find_namespace_packages()
,这应该在python 3.3+中使用