You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Python Wheel控制台入口点无法正常工作的问题求助

Windows下Python Wheel控制台入口点无法正常工作的问题求助

我最近在给我的测试助手脚本制作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")
    # 更多无关代码在这里

if __name__ == '__main__':
    runTests()

setup.py的内容:

from setuptools import find_packages, setup
from pathlib import Path

# 读取README文件内容
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

我用这个命令构建Wheel包:

py -m pip wheel --no-deps -w dist .

用pip安装后,我检查了site-packages目录里的内容没问题,但执行py -m testrunner -h时就会出现上面提到的错误。有没有大佬能帮我看看问题出在哪?

备注:内容来源于stack exchange,提问作者Jonny Schubert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 11:02:58