R
Railway10mo ago
Iceman

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
Percy
Percy10mo ago
Project ID: N/A
Iceman
Iceman10mo ago
N/A
Brody
Brody10mo ago
from following their docs this is the nixpacks.toml file i came up with, untested, so let me know if it works
[phases.setup]
aptPkgs = ['...', 'libpango-1.0-0', 'libpangoft2-1.0-0', 'libjpeg-dev', 'libopenjp2-7-dev', 'libffi-dev', 'libglib2.0-dev']
[phases.setup]
aptPkgs = ['...', 'libpango-1.0-0', 'libpangoft2-1.0-0', 'libjpeg-dev', 'libopenjp2-7-dev', 'libffi-dev', 'libglib2.0-dev']
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
in a railway.toml file add this
[build]
nixpacksVersion = "1.15.0"
[build]
nixpacksVersion = "1.15.0"
Iceman
Iceman10mo ago
That got it working again so it could publish the image but then it gave me the same gobject error as before
Brody
Brody10mo ago
updated
Iceman
Iceman10mo ago
Tried it but got exactly the same Gobject error
Brody
Brody10mo ago
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
Iceman
Iceman10mo ago
I've not tried it with docker yet. How can I share the repo with you?
Brody
Brody10mo ago
send me the link to your repo set to public
Iceman
Iceman10mo ago
GitHub
GitHub - nickrogerson1/linguoai-git: Linguoai website
Linguoai website. Contribute to nickrogerson1/linguoai-git development by creating an account on GitHub.
Brody
Brody10mo ago
are you using all 123 dependencies?
Iceman
Iceman10mo ago
Not now, some are redundant but it does use a lot Not got around to removing the redundant ones yet
Brody
Brody10mo ago
please go through and do that, if i had a dime for everytime an unused python dependency caused issues lol
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
just go through and remove deps you arent using, dont keep trying to deploy to railway
jr
jr10mo ago
Will also add this to list of things that are having issues with Nixpacks 1.16.0
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
okay I'll circle back around to this tomorrow as it's very late for me right now
Iceman
Iceman10mo ago
Okay, no worries. Thanks for your help
Brody
Brody10mo ago
just place this in a Dockerfile file in your project
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 python manage.py migrate && python manage.py collectstatic --noinput && gunicorn linguoai.wsgi
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 python manage.py migrate && python manage.py collectstatic --noinput && gunicorn linguoai.wsgi
Iceman
Iceman10mo ago
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 now
Iceman
Iceman10mo ago
These are the build logs
Brody
Brody10mo ago
no worries! show me the dockerfile you have now please
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
little tip, wrap multiline code in triple backticks
Iceman
Iceman10mo ago
ah ok, thanks
Brody
Brody10mo ago
please do that this repo isn't here anymore?
Iceman
Iceman10mo ago
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
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
Should be now I put it in triple backticks but still looked the same It's in one box now
Brody
Brody10mo ago
there's no dockerfile in that repo? did you send me the wrong repo by chance?
Iceman
Iceman10mo ago
I've not uploaded it yet I removed it to test some other stuff
Brody
Brody10mo ago
put it in please, and delete the procfile, railway.toml, and nixpacks.toml
Iceman
Iceman10mo ago
ok, done
Brody
Brody10mo ago
okay now that would have triggered a build, let me know how that goes
Iceman
Iceman10mo ago
It's failed already Doesn't seem to like the Start Command again Do you need the logs?
Brody
Brody10mo ago
well are the logs the exact same as the log you already sent?
Iceman
Iceman10mo ago
Almost it's reverted back to the previous command now
Brody
Brody10mo ago
do you perhaps have a start command set in the service settings?
Iceman
Iceman10mo ago
Yeah
Brody
Brody10mo ago
definitely remove it make sure you save by clicking the check mark
Iceman
Iceman10mo ago
Does a Dockerfile not knock all these files and commands out? Yeah, it's redeploying
Brody
Brody10mo ago
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
Iceman
Iceman10mo ago
Okay, looks like we're moving It's starting to deploy
Brody
Brody10mo ago
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
Iceman
Iceman10mo ago
yeah, sure
Brody
Brody10mo ago
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
Iceman
Iceman10mo ago
It's deployed but I'm just testing it Seems to be a bug
Brody
Brody10mo ago
logs?
Iceman
Iceman10mo ago
Weasyprint isn't finishing the PDF It's hanging
Brody
Brody10mo ago
looks like a code issues, it says you are missing a required parameter for FPDF.add_font()
Iceman
Iceman10mo ago
Yeah, I was testing a few other functions as well but that doesn't have anything to do with Weasyprint
Brody
Brody10mo ago
haha it's still a code issue though please fix
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
I understand but it's causing your app to crash so it does need to be fixed
Iceman
Iceman10mo ago
the other error was pandoc can that just be added in in the 1st RUN?
Brody
Brody10mo ago
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
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
ah so everything works?
Iceman
Iceman10mo ago
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
Brody
Brody10mo ago
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
Iceman
Iceman10mo ago
okay, where did you get this from:
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
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
these package names
Brody
Brody10mo ago
from weasyprint's docs give this dockerfile a try
FROM python:3.11

ENV PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install -y --no-install-recommends \
parallel \
gcc \
libpango-1.0-0 \
libpangoft2-1.0-0 \
libjpeg-dev \
libopenjp2-7-dev \
libffi-dev \
libglib2.0-dev \
pandoc

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

RUN apt-get purge -y --auto-remove gcc

COPY . ./

CMD parallel --ungroup --halt now,fail=1 ::: \
"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"
FROM python:3.11

ENV PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install -y --no-install-recommends \
parallel \
gcc \
libpango-1.0-0 \
libpangoft2-1.0-0 \
libjpeg-dev \
libopenjp2-7-dev \
libffi-dev \
libglib2.0-dev \
pandoc

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

RUN apt-get purge -y --auto-remove gcc

COPY . ./

CMD parallel --ungroup --halt now,fail=1 ::: \
"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"
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
Iceman
Iceman10mo ago
Yeah, was about to chase up for this but you beat me to it. Thanks again!
Brody
Brody10mo ago
let me know if that dockerfile works for you
Iceman
Iceman10mo ago
yeah, I've tested it and it seem to work fine
Brody
Brody10mo ago
awsome