What is setup.py in Python? - GeeksforGeeks
In Python, setup.py is a module used to build and distribute Python packages. It typically contains information about the package, such as its name, version, and dependencies, as well as instructions for building and installing the package. This information is used by the pip tool, which is a package manager for Python that allows users to install and manage Python packages from the command line. By running the setup.py file with the pip tool, you can build and distribute your Python package so that others can use it.
Example
Following is an example of a setup.py file for a simple Python package called my_package.
First, create a folder named ‘my_package’ with a python file named ‘__init__.py’ inside it. This ‘__init__.py’ file will be the root of the my_package and will contain all the functions and classes in the my_package module. Now your directory structure should look something like this:
Resulting directory structure
Now, add the following contents to the setup.py file:
|
Here, the setup function is called with several arguments that provide information about the package. The name and version arguments specify the package name and version, while the description and author arguments provide a brief description of the package and the author’s name. The author_email argument specifies the author’s email address, and the packages argument indicates which packages should be included in the distribution. Finally, the install_requires argument specifies the package dependencies, which are other packages that must be installed in order for the my_package package to work properly.
# DOC:
Distributing Python Modules (Legacy version) — Python 3.10.13 documentation
Python packaging user guide:
Overview of Python Packaging - Python Packaging User Guide