🌐
ChristopherGS
christophergs.com › python › 2016 › 12 › 11 › python-setuptools
Using Python setuptools
December 11, 2016 - Add the following to the script, ... You now have the bare minimum to use setuptools. To run your setup.py file the command format is: python setup.py <some_command> <options> to view the available commands you can type: python setup.py --help-commands ·...
🌐
PyPA
setuptools.pypa.io › en › latest › userguide › quickstart.html
Quickstart - setuptools 84.0.0 documentation
Setuptools supports automatic creation of scripts upon installation, that run code within your package if you specify them as entry points. An example of how this feature can be used in pip: it allows you to run commands like pip install instead of having to type python -m pip install.
🌐
PyPA
setuptools.pypa.io › en › latest › setuptools.html
Building and Distributing Packages with Setuptools - setuptools 84.0.0 documentation
Setuptools is a collection of enhancements to the Python distutils that allow developers to more easily build Python packages, including those that have dependencies on other packages and C/C++ extension modules.
🌐
Stack Overflow
stackoverflow.com › questions › 35566376 › how-to-use-setuptools-to-install-a-python-script-for-windows-command-line
How to use setuptools to install a python script for windows command line? - Stack Overflow
How would I go about making my script useable on the windows command line from a pip install or setup.py install? ... Copy#!/usr/bin/env python from setuptools import setup setup(name='youtube-song-downloader', version='0.1', description='A program used to search and download songs from Youtube.', url='https://github.com/dszopa/youtube-song-downloader', author='Daniel Szopa', author_email='dszopa@iastate.edu', license='MIT', install_requires=[ 'youtube_dl', 'google-api-python-client', 'pytest', ], packages=['ytsdl'], scripts=['bin/youtube-song-downloader'], include_package_data=True, zip_safe=False)
🌐
Python Packaging
packaging.python.org › guides › distributing-packages-using-setuptools
Packaging and distributing projects - Python Packaging User Guide
Set packages to a list of all packages in your project, including their subpackages, sub-subpackages, etc. Although the packages can be listed manually, setuptools.find_packages() finds them automatically. Use the include keyword argument to find only the given packages.
🌐
PyPI
pypi.org › project › setuptools
setuptools · PyPI
Most extensible Python build backend with support for C/C++ extension modules · pip install setuptools Copy PIP instructions · See the Quickstart and the User’s Guide for instructions on how to use Setuptools.
Find elsewhere
🌐
Setuptools
setuptools.pypa.io › en › stable › userguide › quickstart.html
Quickstart - setuptools 80.9.0.post20250527 documentation
Setuptools supports automatic creation of scripts upon installation, that run code within your package if you specify them as entry points. An example of how this feature can be used in pip: it allows you to run commands like pip install instead of having to type python -m pip install.
🌐
DEV Community
dev.to › wangonya › using-setuptools-to-package-your-python-app-18p4
Using setuptools to package your Python app - DEV Community
August 5, 2019 - import click @click.command() def hello(): click.echo('Hello World!') ... from setuptools import setup setup( name='hello-world-cli', py_modules=['helloworld'], install_requires=[ 'Click', ], entry_points=''' [console_scripts] hello=helloworld:hello ''', )...
🌐
Reddit
reddit.com › r/learnpython › python setuptools with many commands
r/learnpython on Reddit: python setuptools with many commands
June 30, 2023 -

It's normal to extend python with C/C++. I have the need to extend with C#.

It works well to call C# libraries with the pythonnet package.

What I'm struggling with now is to create a python package that contains the C# binaries. Specifically it's setuptools that I'm unsure about.

I'm used to building my packages with:

python setup.py bdist_wheel

I have created a "command" in setup.py that can publish the C# binaries. It can be invoked with

python setup.py publish_dotnet

But how do I combine them? I could do:

python setup.py publish_dotnet
python setup.py bdist_wheel

I.e. running two commands and having bdist_wheel assume the publish_dotnet command has been run. But I'm hoping there is a way to boil it down to running one command that both builds the dotnet code and package it into a wheel.

For reference, here's a setup.py that adds arbitrary files to the wheel:

from setuptools import setup, find_namespace_packages
setup(
    packages=find_namespace_packages(where="src"),
    package_dir={"": "src"},
    package_data={
        "mypkg1.data": ["*.*"],
    }
)

Here's the setup.py that builds the dotnet code:

import os
import shutil
import distutils
from setuptools import Command, find_packages, setup
from setuptools.command.build import build


class publish_dotnet(Command):
    user_options = [
        ("dotnet-config=", None, "dotnet build configuration"),
        (
            "inplace",
            "i",
            "ignore build-lib and put compiled extensions into the source " + "directory alongside your pure Python modules",
        ),
    ]

    def initialize_options(self):
        self.announce("publish_dotnet.initialize_options", level=distutils.log.INFO)
        self.dotnet_config = None
        self.build_lib = None
        self.inplace = False

    def finalize_options(self):
        self.announce("publish_dotnet.finalize_options", level=distutils.log.INFO)
        if self.dotnet_config is None:
            self.dotnet_config = "release"

        build = self.distribution.get_command_obj("build")
        build.ensure_finalized()
        if self.inplace:
            self.build_lib = "."
        else:
            self.build_lib = build.build_lib

    def run(self):
        dotnet_publish_dir = "dotnet_published_binaries"

        self.announce("deleting old artifacts...", level=distutils.log.INFO)

        if os.path.isdir(dotnet_publish_dir):
            shutil.rmtree(dotnet_publish_dir)

        self.announce("publishing...", level=distutils.log.INFO)
        cmd = ["dotnet", "publish", "-o", dotnet_publish_dir, r"src\csharp\ClassLibrary1\ClassLibrary1.csproj"]
        self.spawn(cmd)


setup(
    cmdclass={"publish_dotnet": publish_dotnet},
)
🌐
PyPA
setuptools.pypa.io › en › latest
setuptools 84.0.0 documentation
It helps developers to easily share reusable code (in the form of a library) and programs (e.g., CLI/GUI tools implemented in Python), that can be installed with pip and uploaded to PyPI. Professional support for setuptools is available as part of the Tidelift Subscription.
🌐
Jichu4n
jichu4n.com › posts › how-to-add-custom-build-steps-and-commands-to-setuppy
How To Add Custom Build Steps and Commands To setup.py
October 7, 2014 - % self.pylint_rcfile) def run(self): """Run command.""" command = ['/usr/bin/pylint'] if self.pylint_rcfile: command.append('--rcfile=%s' % self.pylint_rcfile) command.append(os.getcwd()) self.announce( 'Running command: %s' % str(command), level=distutils.log.INFO) subprocess.check_call(command) setuptools.setup( cmdclass={ 'pylint': PylintCommand, }, # Usual setup() args. # ... ) Now, running python setup.py --help-commands will show:
🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-set-up-setuptools-for-python-on-windows
How to set up Setuptools for Python on Windows? - GeeksforGeeks
July 23, 2025 - Step 4: Enter the following command in the command prompt to install Setuptools using pip. ... Step 1: Download the latest source package of Setuptools for Python3 from here.
Top answer
1 of 7
118

Note: The solution below only works when installing a source distribution zip or tarball, or installing in editable mode from a source tree. It will not work when installing from a binary wheel (.whl)


This solution is more transparent:

You will make a few additions to setup.py and there is no need for an extra file.

Also you need to consider two different post-installations; one for development/editable mode and the other one for install mode.

Add these two classes that includes your post-install script to setup.py:

from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install


class PostDevelopCommand(develop):
    """Post-installation for development mode."""
    def run(self):
        develop.run(self)
        # PUT YOUR POST-INSTALL SCRIPT HERE or CALL A FUNCTION

class PostInstallCommand(install):
    """Post-installation for installation mode."""
    def run(self):
        install.run(self)
        # PUT YOUR POST-INSTALL SCRIPT HERE or CALL A FUNCTION

and insert cmdclass argument to setup() function in setup.py:

setup(
    ...

    cmdclass={
        'develop': PostDevelopCommand,
        'install': PostInstallCommand,
    },

    ...
)

You can even call shell commands during installation, like in this example which does pre-installation preparation:

from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install
from subprocess import check_call


class PreDevelopCommand(develop):
    """Pre-installation for development mode."""
    def run(self):
        check_call("apt-get install this-package".split())
        develop.run(self)

class PreInstallCommand(install):
    """Pre-installation for installation mode."""
    def run(self):
        check_call("apt-get install this-package".split())
        install.run(self)


setup(
    ...

P.S. there are no any pre-install entry points available on setuptools. Read this discussion if you are wondering why there is none.

2 of 7
21

Note: The solution below only works when installing a source distribution zip or tarball, or installing in editable mode from a source tree. It will not work when installing from a binary wheel (.whl)


This is the only strategy that has worked for me when the post-install script requires that the package dependencies have already been installed:

import atexit
from setuptools.command.install import install


def _post_install():
    print('POST INSTALL')


class new_install(install):
    def __init__(self, *args, **kwargs):
        super(new_install, self).__init__(*args, **kwargs)
        atexit.register(_post_install)


setuptools.setup(
    cmdclass={'install': new_install},
🌐
Readthedocs
python-packaging.readthedocs.io › en › latest › command-line-scripts.html
Command Line Scripts — Python Packaging Tutorial
setup( ... entry_points = { 'console_scripts': ['funniest-joke=funniest.command_line:main'], } ... ) Again, once the package has been installed, we can use it in the same way. Setuptools will generate a standalone script ‘shim’ which imports your module and calls the registered function.
🌐
Towards Data Science
towardsdatascience.com › home › data science › setup.py vs setup.cfg in python
setup.py vs setup.cfg in Python | Towards Data Science
March 7, 2022 - Serves as the command line interface that enables the execution of packaging commands. ... setup( name='examplepackage' version='1.0.1', author='Giorgos Myrianthous', description='This is an example project', long_description='This is a longer ...
🌐
GitHub
github.com › pypa › setuptools › blob › main › docs › userguide › quickstart.rst
setuptools/docs/userguide/quickstart.rst at main · pypa/setuptools
You can install the latest version of setuptools using :pypi:`pip`: ... Most of the time, however, you don't have to... Instead, when creating new Python packages, it is recommended to use a command line tool called :pypi:`build`. This tool ...
Author: pypa