Making your package portable

Software Engineering Principles in Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Steps to portability

setup.py file

requirements.txt file

Software Engineering Principles in Python

Portable package structure

Package Structure

Software Engineering Principles in Python

Contents of requirements.txt

working in work_dir/requirements.txt

# Needed packages/versions
matplotlib
numpy==1.15.4
pycodestyle>=2.4.0

working with terminal

datacamp@server:~$ pip install -r requirements.txt
Software Engineering Principles in Python

Contents of setup.py

from setuptools import setup

setup(name='my_package',
      version='0.0.1',
      description='An example package for DataCamp.',
      author='Adam Spannbauer',
      author_email='[email protected]',
      packages=['my_package'],
      install_requires=['matplotlib',
                        'numpy==1.15.4',
                        'pycodestyle>=2.4.0'])
Software Engineering Principles in Python

install_requires vs requirements.txt

working inwork_dir/requirements.txt

# Specify where to install requirements from
--index-url https://pypi.python.org/simple/

# Needed packages/versions
matplotlib
numpy==1.15.4
pycodestyle>=2.4.0

Documentation: install_requires vs requirements files

Software Engineering Principles in Python

pip installing your package

datacamp@server:~/work_dir $ pip install .
Building wheels for collected packages: my-package
  Running setup.py bdist_wheel for my-package ... done
Successfully built my-package
Installing collected packages: my-package
Successfully installed my-package-0.0.1
Software Engineering Principles in Python

Let's Practice

Software Engineering Principles in Python

Preparing Video For Download...