I am new to Python and having some trouble understanding what role Distutils plays when it comes to installing and using pure Python packages and modules. I recently downloaded Kaltura's Python client for its API and it came with the standard Distutils setup script. It also came with the source Python scripts that comprise the various modules themselves. I ran the Distutils setup script with the install command, and the test code provided seems to work, but I can't get the client to load properly and work in other contexts.
I'm confused about where Distutils fits in here. I already have the modules, they were part of the archive I downloaded. Do I even need to run Distutils setup/install? Can't I just import the modules directly? What's the point of running the install?
Not sure if this helps, but here is the setup script:
from distutils.core import setup
setup(
name='KalturaClient',
version='1.0.0',
url='http://www.kaltura.com/api_v3/testme/client-libs.php',
packages=['KalturaClient', 'KalturaClient.Plugins'],
license='AGPL',
description='A Python module for accessing the Kaltura API.',
long_description=open('README.txt').read(),
)
I see the distutils setup.py
basically as a convenience for moving things to the right directory.
The install
command moves all modules to a user-wide (or system-wide, if run as root) accessible and known place, such that you don't have to care about the actual path, when importing the module. For simple setups this is not absolutely necessary. But if your setup becomes more complicated it is nice to have. Some examples:
You have a couple of modules you update regularly used in more than one place. Without setup you would have to copy them either to project specific or global reachable directories by hand all the time
You have different versions of a module for different projects. You create a virtualenv
and install using setup.py
into that virtualenv.
When doing this by hand it is an error-prone work where you have to get all paths right and remember right. With distutils it is no hassle.
Of course it is not a real big thing to do it by hand for pure-python modules. That of course changes for more complex modules, that bind to C code etc.
If you are familiar with Linux distributions, you can see it as equivalent to the package-managment tool of your distribution (dpkg, rpm, etc.).
Additionally the setup.py is used by pip and the PyPI module repository to automatically download and install Python packages.