Depend on psycopg2-binary instead of psycopg2.#357
Depend on psycopg2-binary instead of psycopg2.#357torotil wants to merge 1 commit intomysociety:masterfrom
Conversation
|
I understand why this would be nice for development/ease of setup; however psycopg2 says, at https://www.psycopg.org/docs/install.html#install-from-source "If you are the maintainer of a published package depending on psycopg2 you shouldn’t use ‘psycopg2-binary’ as a module dependency. For production use you are advised to use the source distribution." |
|
Thanks I didn’t know that. Is there a way of specifying it only as dev-dependency then? |
|
Python packaging, as far as I know, does not have such a concept. If you wish to use the binary package, you can install it in your venv first, manually, or (I guess) by specifying it first in your own requirements.txt Looking at psycopg/psycopg2#674, I don't want to get involved with that :) |
|
This reliance massively increases build times. When developing locally in containers or in CI, the build time for psycopg is 5+ minutes. Can it be a decision made with an environment variable? |
|
Hi @RossLYoung - that sounds odd, https://github.com/mysociety/mapit/actions/runs/21130062639/job/60758899547 only takes 25 seconds to install all the python packages in that Action, including psycopg2 as part of it. What is your install doing in all that time? |
|
Hi @dracos - simply running 'docker compose build' has my beefy CPU at 100% for at least 5 minutes whenever I update any dependencies and need a full build. Is your CI caching the pip install layer?
I've submitted #440 which removes the psycopg2 dependency if you're using mapit as a library, and includes both psycopg versions if your are running it standalone. I think the only changes required would be to update the docs to say something like |
No, there is no caching of which I'm aware. You can see the action at https://github.com/mysociety/mapit/blob/master/.github/workflows/default.yml Your screenshot doesn't provide any extra information as to what it's doing; a plain install of psycopg2 (and django-mapit is the same) from scratch on a normal server takes the same time as our CI: Does your build provide any logging or anything to say what it is doing during the time? Anyway, wherever the issue lies, thanks for the PR; why can't we just switch it to depend upon psycopg and psycopg[binary] are pretty instant here; I see psycopg[c] takes 45s rather than 15s for psycopg2, who knows why, but still, nothing like 5 minutes. |
|
I'm not sure what is going on with my build times. I'm using UV, Python 3.14, in an Ubuntu 24 docker container.
I was suggesting that we don't depend on it at all. The only change would be updating the install docs to We could also update the advice to "pip install django-mapit" as it will install v3.0 from Nov 2020. |
|
I've opened #442 which uses changes from your PR, but does keep |

This makes it possible to install the Python venv without the need to compile anything.
fixes #323