简体   繁体   中英

Creating a Python Package That Adds Script to Path

I'm working on a Python package, and I'd like to add a script to the users PATH once they install it. I'm not sure if this is the correct terminology, so here's an example of what I'd like to accomplish:

  1. user installs package via pip
pip install my-pkg
  1. once installed the user can enter the following in their termial
my-pkg start
  1. this then creates a settings.py/index.html files in the current dir

This is similar to running django-admin startproject . Thanks for any help.

You can do this by specifying that script in your setup.py as an entrypoint .

If using a pyproject.toml, the equivalent is a plugin .

Just to expand on @Ray Johns answer, this is what it would look like inside your setuptools.setup function.

entry_points = {
        'console_scripts': [
            'command = my-pkg.module:func',                  
        ], 
}

I'm working on a Python package, and I'd like to add a script to the users PATH once they install it. I'm not sure if this is the correct terminology, so here's an example of what I'd like to accomplish:

  1. user installs package via pip
pip install my-pkg
  1. once installed the user can enter the following in their termial
my-pkg start
  1. this then creates a settings.py/index.html files in the current dir

This is similar to running django-admin startproject . Thanks for any help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM