So, I'm developing a project, and I'm writing setup.py script for it, using distutils. I'm using CPython3.3.

I use some libraries that have invalid distributions in PyPI, so they have to be installed by cloning repo and running setup.py manually (I've tried many things, both libraries help said I just need to use git instead of PyPI, so why I need to do that this way is not a question here).

So, I've used some subprocess magic, and created script that clones repos and runs "setup.py install" in them. It also runs apps setup.py, after ensuring that broken libs are already installed other way. It is easy to convert to several methods, and will be enhanced in few moments. At the moment my app may be installed by running this script (I called it build.py).


How do I create a hook in my setup.py script (for my app) that will run methods installing things from github when (and ONLY when) "install" argument was passed to apps setup.py?

What I've tried

I tried googling phrases like "how do I hook setup.py" - more or less general, I tried several queries. Nothing has been found.

Also, I tried to analyze distutils source, to find some way, but that also got me nowhere.

Haven't tried it yet, but I know it is doable - at the beginning of setup.py script checking whether conditions like "it is ran as main script" and "'install' keyword is in sys.argv" are true, and if so - running my git-related methods, but this is ugly as hell.


1 Answer 1


Do not handle installation of dependencies in your setup.py. Only handle packaging your own project, and leave dependencies to the specialized tools such as pip and buildout.

If in the future those packages see better releases on PyPI, all you need to do is change your installation instructions, not create a new release with a new setup.py, even though no functionality changed.

You can provide a requirements.txt file for pip installation, or a buildout.cfg for buildout, both of which can include information to let the tool pull dependencies directly from github instead of from PyPI.

See https://caremad.io/blog/setup-vs-requirement/ for a good blog post on the same subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.