讓你的套件可攜帶

Python 的軟體工程原則

Adam Spannbauer

Machine Learning Engineer at Eastman

可攜性的步驟

setup.py 檔案

requirements.txt 檔案

Python 的軟體工程原則

可攜式套件結構

套件結構

Python 的軟體工程原則

requirements.txt 內容

work_dir/requirements.txt 作業

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

terminal 操作

datacamp@server:~$ pip install -r requirements.txt
Python 的軟體工程原則

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'])
Python 的軟體工程原則

install_requires 與 requirements.txt

work_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

文件: install_requires 與 requirements 檔案

Python 的軟體工程原則

用 pip 安裝你的套件

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
Python 的軟體工程原則

一起來練習吧!

Python 的軟體工程原則

Preparing Video For Download...