What Is Setup.Py

What is setup.py?

setup.py is a python file, the presence of which is an indication that the module/package you are about to install has likely been packaged and distributed with Distutils, which is the standard for distributing Python Modules.

This allows you to easily install Python packages. Often it's enough to write:

$ pip install . 

pip will use setup.py to install your module. Avoid calling setup.py directly.

https://docs.python.org/3/installing/index.html#installing-index

setup.py - metadata-generation-failed

You've forgotten to add readme.md as a data file. Please note that only README* files are automatically included. Rename your readme.md file to README.md or add it as a data file using MANIFEST.in.

requirements.txt vs setup.py

requirements.txt:

This helps you to set up your development environment.

Programs like pip can be used to install all packages listed in the file in one fell swoop. After that you can start developing your python script. Especially useful if you plan to have others contribute to the development or use virtual environments.
This is how you use it:

pip install -r requirements.txt

It can be produced easily by pip itself:

pip freeze > requirements.txt

pip automatically tries to only add packages that are not installed by default, so the produced file is pretty minimal.


setup.py:

This helps you to create packages that you can redistribute.

The setup.py script is meant to install your package on the end user's system, not to prepare the development environment as pip install -r requirements.txt does. See this answer for more details on setup.py.


The dependencies of your project are listed in both files.

Python setup.py develop vs install

python setup.py install is used to install (typically third party) packages that you're not going to develop/modify/debug yourself.

For your own stuff, you want to first install your package and then be able to frequently edit the code without having to re-install the package every time — and that is exactly what python setup.py develop does: it installs the package (typically just a source folder) in a way that allows you to conveniently edit your code after it’s installed to the (virtual) environment, and have the changes take effect immediately.


Note: It is highly recommended to use pip install . (regular install) and pip install -e . (developer install) to install packages, as invoking setup.py directly will do the wrong things for many dependencies, such as pull prereleases and incompatible package versions, or make the package hard to uninstall with pip.

Update:

The develop counterpart for the latest python -m build approach is as follows (as per):

Sample Image



Related Topics



Leave a reply



Submit