admin管理员组

文章数量:1333390

I have been developing a small python-based package that contains multiple scripts that are to be used as command line tools in linux environment.

This has a typical package structure:

MyPackage/
├── LICENSE
├── README.md
├── MyPackage
│   ├── __init__.py
│   ├── command1.py
│   ├── command2.py
│   ├── command3.py
│       ...
├── pyproject.toml
├── setup.py

I want for the commands to be found as command line tools after installing this package by pip install .

However, after installation, my environment does not find the commands. Checking a lot of resources, it seems that the problem is likely to be with the setup.py file, or more specifically, with entry points. If entry points are set properly, the commands are supposed to be found at bin directory, but they are not found. pip show MyPackage prints the following directory only: /home/My/../python3.12/site-packages/MyPackage

The following is my setup.py

import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="MyPackage",
    version="0.0.1",
    author="Me",
    description="my package",
    entry_points={
        'console_scripts': [
            'command1=MyPackagemand1:main',
            'command2=MyPackagemand2:main',
            'command3=MyPackagemand3:main'
        ],
    },
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent"],
    python_requires='>=3.6',
    install_requires=['numpy>=1.17.2']

Of course, I can add some files to bin that calls the commands of my package. But I want to make it pip available for other users.

I am sure this is not a problem of my environment since I tested it with multiple devices. I am using conda, but I am not sure if this is relevant.

I tried to install the package as user specific by adding --user with pip installation as suggested by some people online. However, it did not resolve the issue.

Could you please give me some help make it easily installable as a command line tool package?

本文标签: pythonEntrypoints problem with setuptools for making my script executableStack Overflow