kms333
kms333

Reputation: 3257

Execute python script from a installed package

I have a Python package that contains a script:

pip show -f my-package

Results in

my-package-path/script.py

I would like to execute script.py, something like:

pip install my-package
python3 my-package-path.script.py

But it doesn't work. What's the standard way of doing this?

Upvotes: 1

Views: 457

Answers (1)

rasjani
rasjani

Reputation: 7970

If you access and modify my-package setup.py (if setuptools is used) - you could add entry_points to setup() call and if thats done correctly, you can run the script directly as its added to the path. Example:

NAME="AISTool"

setup(
    name=f"{NAME}",
    # ... extra stuff removed ...
    entry_points={
        'console_scripts': [
            f'{NAME}=AISTool.main:main'
        ],
    },
    # ... extra stuff removed ...
)

Now, when that package gets installed, there will be an executable called AISTool which runs main() method from AISTool.main

Upvotes: 1

Related Questions