-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot pip3 install orjson
in Docker currently (alpine linux)
#98
Comments
OR does rust not have a recent 'stable' build which understands |
pip3 install orjson
in Docker currentlypip3 install orjson
in Docker currently (alpine linux)
Alpine Linux cannot use wheels from PyPI. This isn't an orjson-specific issue, any binary wheel will fail to install. You're better off just not using Alpine for this reason (https://pythonspeed.com/articles/alpine-docker-python/ talks about this in more detail.) |
K. Article seems to know what they're talking about, but there goes my 10MB container for a 350MB Debian container, just to run ... orjson. What tells you that PyPl / wheels are to blame in those logs? ( for my edification ) I'll run json for now since I'm not yet processing 2^32 records. python3 runs fine in Alpine for me. |
It's not the logs, it's external knowledge. Most Linux distributions use glibc, Alpine Linux uses musl, so Alpine's Python disables binary wheels since they are built for glibc and can therefore be incompatible. |
damn, lost 4 hours trying to fix this in order to save a few hundred MBs using alpine. |
Just want to mention that if you copy the stuff compiled into site-packages and sometimes also binaries from /user/local/bin into a second stage alpine image, the resulting image won't be bigger since you just dropped all compile dependencies, again. You just need to make sure you install the slim version of the dependencies again in the final image. So, result can in fact be around 100 MB. Wile to compile stage, image can rack up to 1 Gb+. Yes, the build time will be significantly higher, but we have layer caching. It is OK for a production image, IMO. FROM python:3.9-alpine as builder
RUN apk add --no-cache gcc g++ musl-dev rust cargo patchelf
RUN python -m pip install orjson
FROM python:3.9-alpine
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
RUN apk add --no-cache libstdc++
CMD ["python", "-c", "import orjson; print(orjson.dumps({'number': 1}))"] $ docker build -t test .
$ docker run test
b'{"number":1}' With this Dockerfile the builder stage is as big as 1.28 GB, but the final image is only 58 MB. The first build took around 10 minutes on my machine. But after caching, when changing lets say only the program to run, it only takes seconds. Edit: since recently, we seem to need to add patchelf ourselves. See #227. I have added it to the dockerfile. |
I think cibuildwheel now has support for musllinux wheels. |
Hi I am using python 3.6 in my project and would like to switch from simplejson to orjson.
|
This is a response specifically to the previous comment about orjson 3.6.1 triggering the PEP 517 compliance error. This closed issue thread has the top hit in results that Google displays to me when searching for that error message for the last couple of days. I do not have a solution that will get 3.6.x working, I present this workaround. For me the error occurs specifically with orjson 3.6.x when using Python 3.11.7 with pip 24.1.2 on RHEL8, and doesn't occur with orjson 3.7 or later in the same environment. My project also works using orjson 3.6.x in a Docker container based on python:3.8 official image (Debian 'bookworm'), with cargo installed via apt-get. Since updating requirements.txt with WFM, YMMV. Sincere apologies to the orjson developers for adding this off-topic comment to an ancient closed thread. |
I get this:
When called from
docker-compose build
with alpine linux 3.7Not possible to distribute orjson without the need to compile?
If I try on latest alpine linux:
The text was updated successfully, but these errors were encountered: