Can't install Weasyprint in Django
Hi, I'm trying to install Weasyprint in my Dango project. I've got it working locally but can't seem to upload it to the server and get this error:
OSError: cannot load library 'gobject-2.0-0': gobject-2.0-0: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
/bin/bash: line 1: -----: command not found
This is my nixpacks.toml:
[phases.setup]
nixPkgs = ["...", "pango", "libffi" ]
I've been going through their installation guide but can't figure out what I'm missing. This is the guide: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html
Any help would be appreciated.71 Replies
Project ID:
N/A
N/A
from following their docs this is the nixpacks.toml file i came up with, untested, so let me know if it works
Just got this error:
ERROR: failed to solve: process "/bin/bash -ol pipefail -c apt-get update && apt-get install -y --no-install-recommends libpango-1.0-0 libpangoft2-1.0-0 libjpeg-dev libopenjp2-7-dev libffi-dev" did not complete successfully: exit code: 1
Error: Docker build failed
Build failed
full build logs please https://bookmarklets.up.railway.app/log-downloader/
in a railway.toml file add this
That got it working again so it could publish the image but then it gave me the same gobject error as before
updated
Tried it but got exactly the same Gobject error
my recommendation would be to move to a dockerfile based build
i can write one for you, i would need to see your repo though
I've not tried it with docker yet. How can I share the repo with you?
send me the link to your repo set to public
GitHub
GitHub - nickrogerson1/linguoai-git: Linguoai website
Linguoai website. Contribute to nickrogerson1/linguoai-git development by creating an account on GitHub.
are you using all 123 dependencies?
Not now, some are redundant but it does use a lot
Not got around to removing the redundant ones yet
please go through and do that, if i had a dime for everytime an unused python dependency caused issues lol
I've been fixing other stuff so not had time
but I tried to remove some I thought were redundant and then the build kept failing
just go through and remove deps you arent using, dont keep trying to deploy to railway
Will also add this to list of things that are having issues with Nixpacks 1.16.0
I deleted the local environment and readded them one by one. It still came to 106.
I then tried to upload it to Railway and still got the same Gobject error
okay I'll circle back around to this tomorrow as it's very late for me right now
Okay, no worries. Thanks for your help
just place this in a
Dockerfile
file in your project
Hi, I've been away over the weekend so only just been able to run this now
This is the first time I've tried it with Docker so I'm pretty confused
Looks like the CMD line is supposed to be the Start Command so I changed it to the one I have been using
celery -A linguoai worker --loglevel=info & python manage.py migrate && python manage.py collectstatic && daphne --bind 0.0.0.0 --port $PORT linguoai.asgi:application
But it's telling me it's invalid
So basically stuck there nowThese are the build logs
no worries!
show me the dockerfile you have now please
FROM python:3.11
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpango-1.0-0 \
libpangoft2-1.0-0 \
libjpeg-dev \
libopenjp2-7-dev \
libffi-dev \
libglib2.0-dev
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
RUN apt-get purge -y --auto-remove gcc
COPY . ./
CMD celery -A linguoai worker --loglevel=info & python manage.py migrate && python manage.py collectstatic && daphne --bind 0.0.0.0 --port $PORT linguoai.asgi:application
little tip, wrap multiline code in triple backticks
ah ok, thanks
please do that
this repo isn't here anymore?
Should be now
I put it in triple backticks but still looked the same
It's in one box now
there's no dockerfile in that repo? did you send me the wrong repo by chance?
I've not uploaded it yet
I removed it to test some other stuff
put it in please, and delete the procfile, railway.toml, and nixpacks.toml
ok, done
okay now that would have triggered a build, let me know how that goes
It's failed already
Doesn't seem to like the Start Command again
Do you need the logs?
well are the logs the exact same as the log you already sent?
Almost
it's reverted back to the previous command now
do you perhaps have a start command set in the service settings?
Yeah
definitely remove it
make sure you save by clicking the check mark
Does a Dockerfile not knock all these files and commands out?
Yeah, it's redeploying
unfortunately it doesn't, seems counterintuitive that the start command in the service settings can override it but theres a good reasons to allow that too
Okay, looks like we're moving
It's starting to deploy
awesome
now since I found out you are running celery in the same service, I'd like to further improve that dockerfile if you don't mind
yeah, sure
what you have now should work, but railway won't be able to restart celery if it where to crash since you are running it in the background and railway can't monitor that for failures, it would only be monitoring daphne
but before that, let's make sure what you have now works, so keep me updated on that please
It's deployed but I'm just testing it
Seems to be a bug
logs?
Weasyprint isn't finishing the PDF
It's hanging
looks like a code issues, it says you are missing a required parameter for
FPDF.add_font()
Yeah, I was testing a few other functions as well but that doesn't have anything to do with Weasyprint
haha it's still a code issue though
please fix
they partially use the same function so that function is a bit of a mess at the moment as I've just been trying to get Weasyprint to work
Plus I wasn't sure if I was gonna have to abandon it
I understand but it's causing your app to crash so it does need to be fixed
the other error was pandoc
can that just be added in in the 1st RUN?
whatever package the error is related to is kinda irrelevant, it is causing your app to crash so it needs to be fixed in code in one way or other, please let me know when you have that fixed so we can proceed with the optimised dockerfile
Okay, I found the problem
I somehow added a Python 2 version of FPDF instead of the Python 3 one
Must have happened when I did that package clear out
ah so everything works?
Well, that error has gone
But still got the same problem with Weasyprint
Just give me 5 minutes to make sure there's not a problem in my cde
Okay, pretty much done
Just need to get Pandoc added into the dockerfile and add that suggestion you were mentioning
perfect well I'm about to start a project at home, so I will get back to you with the modifications later, in the mean time feel free to do whatever needs to be done to the dockerfile to get your stuff working
okay, where did you get this from:
these package names
from weasyprint's docs
give this dockerfile a try
for context, parallel will run celery and django in parallel and will fail fast if either service crashes allowing railway to restart the deployment
ideally youd want to run celery in a separate railway service but this is the best way i can think of to run both on one service
Yeah, was about to chase up for this but you beat me to it. Thanks again!
let me know if that dockerfile works for you
yeah, I've tested it and it seem to work fine
awsome