Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packaging Your Python Code [duplicate]

Tags:

python

I wish to package a utility that I have created that depends on Pillow, a port of the Python Imaging Library. Is there a way to include Pillow in my own package or to automatically install Pillow upon running the setup script?

like image 819
Malik Brahimi Avatar asked Jul 10 '26 04:07

Malik Brahimi


1 Answers

Python 3 mainly uses pip for installing packages. This is based off of setuptools and distribute. You would create the setup.py script with the requirement specified. 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 build an executable then the process if fairly similar to the standard setup.py file approach only you use cx_freeze.

like image 53
justengel Avatar answered Jul 13 '26 10:07

justengel