Today, I spent more than two hours trying to figure out why, despite
things working out fine in my development scikits.learn folder,
python setup.py install would completely ignore the module I
refactored into a subpackage.
I imagined that simply adding it to the parent
attribute would do, I kind of thought that setuptools automatically
finds the subpackages.
At first I thought of looking in
setup.py, but I only examined the one
in the topmost directory, which, in the case of scikits.learn, is two
degrees of separation away from the actual setup.py that takes care of
subpackages (ie. I was looking at
/setup.py instead of
/scikits/learn/setup.py). This had me fooled for a while.
The steps to add a working and installable module to a python setuptools-based project are as follows:
- Add a
__init__.pyfile in the folder (ie.
- If the module requires compiling or any special attention, add an
__setup__.pyfile in the folder.
- Update the
__init__.py __all__attribute in the parent folder (ie.
- Update the
setup.pyin the parent folder (ie.
/scikits/learn/setup.py) by adding something like:
Don’t forget to do the same for the tests subfolder!
While wasting so much time due to a simple beginner’s mistake is not very pleasant, I am not frustrated with setuptools. On the contrary, now that I understand it better I can appreciate its flexibility and clarity, when compared to, for example, MSBuild and Visual Studio project files. Just one more reason to love Python!