Minimal Python setup.py with prerequisites

Related: Upload user Python module to PyPi


python -m pip install -e . 

easily and quickly installs complicated lists of prerequisites. The proper place to list prerequisites is inside setup.py instead of requirements.txt, which is for modules needing specific package versions.

Example setup.py

req=['python-dateutil','pytz','nose','xarray','matplotlib','seaborn']
# %%
from setuptools import find_packages
from numpy.distutils.core import setup,Extension

setup(name='MyProg',
      packages=find_packages(),
      author='Joe Smith',
      description='My awesome program prints cool messages.',
      version='1.0',
      url='https://github.com/joe/joesprog',
      install_requires=req,
      python_requires='>=3.5',
      classifiers=[
      'Intended Audience :: Science/Research',
      'Development Status :: 4 - Beta',
      'Topic :: Scientific/Engineering
      'Programming Language :: Python :: 3',
      ],
      )
install_requires
packages to install if not already installed.

Require minimum Python version

The python_requires parameter avoids user confusion if they have an old Python version. Instead of them opening a GitHub issue or just not using your program at all, they’ll get a useful error message.

Classifiers

Classifiers are optional, but help your project be indexed better in PyPi (and hence search engines). Classifiers must be from this official classifiers list or they will fail when uploading your package to PyPi.

setup.py Fortran f2py

Python can easily import Fortran code using f2py. See this f2py example setup.py.

Notes

setup.py reference (excellent)

Leave a Comment