Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python wheel entry point not working as expected on Windows

I’m tryring to setup a python wheel for my testrunner helper script to make it easyly acessible from everywhere on my Windows machine. Therefore I configure a console entry point in my setup.py. I can see the generated entry point in the entry_points.txt but if I’m trying to invoke my script I get the error message.

No module named testrunner.__main__; 'testrunner' is a package and cannot be directly executed

My installer folder tree looks like this

setup.py
README.md
LICENSE.txt
testrunner/
    __init__.py
    testrunner.py
    templates/
        testDesc.json

The testrunner.py looks like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def runTests():
    print("Hello World")
    #More not relevant code here

if __name__ == '__main__':
    runTests()

The setup.py content

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']},
)

And finally the __init__.py

from .testrunner import main, runTests

I build the wheel with the command: py -m pip wheel --no-deps -w dist .
After installation with pip and checking the content in the site-packages directory executing py -m testrunner -h results in No module named testrunner.__main__; 'testrunner' is a package and cannot be directly executed

>Solution :

No module named testrunner.__main__; ‘testrunner’ is a package and cannot be directly executed

You don’t have __main__.py so you cannot do python -m testrunner. To fix the problem:

echo "from .testrunner import runTests" >testrunner/__main__.py
echo "runTests()" >>testrunner/__main__.py

The second problem:

from .testrunner import main, runTests

You don’t have main in testrunner.py. Code if __name__ == '__main__': doesn’t create any main. You only have runTests to import. So change the import to

from .testrunner import runTests

and change your setup.py:

    entry_points={
        'console_scripts': ['testrunner = testrunner:runTests']
    },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading