Packaging Python code

I want to package a utility that I created that depends on Pillow, a port of the Python image library. Is there a way to include Pillow in my own package, or to automatically install Pillow when running the install script?

+3


source to share


1 answer


Python 3 mainly uses pip to install packages. This is based on setuptools customization and distribution. You have to create a setup.py script with the specified requirement. The easiest way is to create a requirements file using pip. http://codeinthehole.com/writing/using-pip-and-requirementstxt-to-install-from-the-head-of-a-github-branch/

Command line:

pip freeze > requirements.txt

      



setup.py

import setuptools
from pip.req import parse_requirements

requirements = [str(ir.req)
                for ir in parse_requirements("requirements.txt", session=uuid.uuid1())
                    if ir.req is not None]
setuptools.setup(..., install_requires=requirements)

      

If you want to create an executable file, then the process, if it looks like a standard setup.py file, is only suitable for using cx_freeze.

+2


source







All Articles