A 'controversial' opinion
Using `setup.py` to pack and distribute your python packages can be quite challenging every so often. Modern tools likePoetry andUV make not only the packaging alot easier, but also help you to manage your dependencies in a very convenient way. UV is particularly notable for being 10-100x faster than traditional tools.
If you want more information about Poetry you can read the following articles:
For a comprehensive guide to UV, the lightning-fast Python package manager, read:UV: The Lightning-Fast Python Package Manager.
The setup script is the center of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.
For a comprehensive guide on handling file and directory paths, which is essential for managing project structures, see theFile and directory Paths page.
Thesetup.py file is at the heart of a Python project. It describes all the metadata about your project. There are quite a few fields you can add to a project to give it a rich set of metadata describing the project. However, there are only three required fields: name, version, and packages. The name field must be unique if you wish to publish your package on the Python Package Index (PyPI). The version field keeps track of different releases of the project. The package’s field describes where you’ve put the Python source code within your project.
This allows you to easily install Python packages. Often it’s enough to write:
python setup.pyinstalland module will install itself.
Our initial setup.py will also include information about the license and will re-use the README.txt file for the long_description field. This will look like:
from distutils.coreimport setupsetup( name='pythonCheatsheet', version='0.1', packages=['pipenv',], license='MIT', long_description=open('README.txt').read(),)Find more information visit theofficial documentation.
Subscribe to pythoncheatsheet.org
Join16,702+ Python developersin a two times a month and bullshit freepublication, full of interesting, relevant links.