我正在尝试为我的 testrunner 帮助脚本设置一个 python wheel,以便从我的 Windows 机器上的任何地方轻松访问它。因此,我在 setup.py 中配置了一个控制台入口点。我可以在 entry_points.txt 中看到生成的入口点,但如果我尝试调用我的脚本,我会收到错误消息。
No module named testrunner.__main__; 'testrunner' is a package and cannot be directly executed
我的安装程序文件夹树如下所示
setup.py
README.md
LICENSE.txt
testrunner/
__init__.py
testrunner.py
templates/
testDesc.json
testrunner.py如下所示
def runTests():
print("Hello World")
#More not relevant code here
if __name__ == '__main__':
runTests()
setup.py内容
from setuptools import find_packages, setup
from pathlib import Path
# read the contents of your README file
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
setup(
name='testrunner',
version='0.3.0',
packages=find_packages(include=['testrunner']),
description='C/C++ test runner',
long_description=long_description,
long_description_content_type='text/markdown',
author='Me',
license="Proprietary",
license_files = ('LICENSE.txt',),
entry_points={
'console_scripts': ['testrunner = testrunner:main']
},
classifiers=[
'Topic :: Software Development :: Build Tools',
'Topic :: Software Development :: Compilers',
'Private :: Do Not Upload',
'Operating System :: Microsoft :: Windows',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research ',
'Intended Audience :: Education ',
'Natural Language :: English',
'License :: Other/Proprietary License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
install_requires=[],
package_data={'':['templates\\*.json']},
)
最后是__init__.py
from .testrunner import main, runTests
我使用以下命令构建轮子:py -m pip wheel --no-deps -w dist .
使用 pip 安装后,检查 site-packages 目录中的内容,执行py -m testrunner -h
结果为No module named testrunner.__main__; 'testrunner' is a package and cannot be directly executed