0

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=MyPackage.command1:main',
            'command2=MyPackage.command2:main',
            'command3=MyPackage.command3: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?

5
  • "If entry points are set properly, the commands are supposed to be found at bin directory…" Said bin directory must be in $PATH to be found without full path. "pip show MyPackage prints the following directory only: /home/My/../python3.12/site-packages/MyPackage" Try pip show --files MyPackage to list all installed files; try pip show --files MyPackage | grep -F /bin/ to get the bin directory; the path is related to the root location which you can get with pip show --files MyPackage | grep "Location:\|/bin/" Commented Nov 20, 2024 at 20:33
  • @phd Thanks for your comment. pip show --files MyPackage shows Location: /home/My/../python3.12/site-packages and no any bin directories. If I understand setuptools correctly, the executable commands must be installed in a bin directory to be available without calling python or anything (like we can call pip command). This is the problem that I want to resolve. Commented Nov 20, 2024 at 22:18
  • @phd More precisely speaking, setuptools should make relevant executable files in bin directory upon package installation if entry points are set up properly. But this is not happening even though (I believe) there is no problem with the entry point lines. Commented Nov 20, 2024 at 22:24
  • Then you need to show us the entire distribution/paclage (a git repository IMO would be the best) or create an minimal reproducible example. Commented Nov 20, 2024 at 22:29
  • @phd I eventually found a problem and it was entirely due to my lack of knowledge of how pip install works. I found that pip install . installs a package based on pyproject.toml but not setup.py, and the commands were not defined in the pyproject. After defining them, I found that the commands are properly located in a bin directory. Thank you for your comments. Commented Nov 20, 2024 at 23:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.