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