R
Railway•11mo ago
meaniebeanie22

absolute newbie: how can I use python 3.12 and django 5.0 when I deploy my app?

project ID: 6ec4e69f-153c-42b1-8399-d4fbd6db04fb I have a django app that runs happily on my computer but when I try and deploy to railway I get errors saying that it is using python38, despite having a runtime.txt file with "Python 3.12.1" in it (I have no idea if that is the right thing to do, but it was what one of the few recent-ish youtube tutorials I could find suggested). Would someone be able to tell me/link to a way for me to use the latest version of python? Thanks!
55 Replies
Percy
Percy•11mo ago
Project ID: 6ec4e69f-153c-42b1-8399-d4fbd6db04fb
Brody
Brody•11mo ago
I have no idea if that is the right thing to do
yes it is, however nixpacks does not currently support python 3.12, the latest nixpacks supports is 3.11
meaniebeanie22
meaniebeanie22OP•11mo ago
3.11 would probably work - would you be able to tell me how to take my django project and wrap it up with a pretty bow for railway? 😄
Brody
Brody•11mo ago
put 3.11 into your runtime.txt and redeploy
meaniebeanie22
meaniebeanie22OP•11mo ago
just 3.11 or "Python 3.11"?
Brody
Brody•11mo ago
either should work
meaniebeanie22
meaniebeanie22OP•11mo ago
found this in the logs after a build fail:
#10 20.59 Building wheels for collected packages: pycairo, svglib

#10 20.59 Building wheel for pycairo (pyproject.toml): started



#10 20.90 error: subprocess-exited-with-error

#10 20.90

#10 20.90 × Building wheel for pycairo (pyproject.toml) did not run successfully.

#10 20.90 │ exit code: 1

#10 20.90 running build

#10 20.90 creating build



#10 20.90 copying cairo/__init__.py -> build/lib.linux-x86_64-cpython-311/cairo

#10 20.90 copying cairo/py.typed -> build/lib.linux-x86_64-cpython-311/cairo

#10 20.90 Package cairo was not found in the pkg-config search path.

#10 20.90 to the PKG_CONFIG_PATH environment variable
#10 20.59 Building wheels for collected packages: pycairo, svglib

#10 20.59 Building wheel for pycairo (pyproject.toml): started



#10 20.90 error: subprocess-exited-with-error

#10 20.90

#10 20.90 × Building wheel for pycairo (pyproject.toml) did not run successfully.

#10 20.90 │ exit code: 1

#10 20.90 running build

#10 20.90 creating build



#10 20.90 copying cairo/__init__.py -> build/lib.linux-x86_64-cpython-311/cairo

#10 20.90 copying cairo/py.typed -> build/lib.linux-x86_64-cpython-311/cairo

#10 20.90 Package cairo was not found in the pkg-config search path.

#10 20.90 to the PKG_CONFIG_PATH environment variable
Brody
Brody•11mo ago
meaniebeanie22
meaniebeanie22OP•11mo ago
Brody
Brody•11mo ago
try adding this as a nixpacks.toml file to your project
[phases.setup]
aptPkgs = ['...', 'libcairo2-dev', 'pkg-config', 'python3-dev']
[phases.setup]
aptPkgs = ['...', 'libcairo2-dev', 'pkg-config', 'python3-dev']
meaniebeanie22
meaniebeanie22OP•11mo ago
in the same dir as runtime.txt?
Brody
Brody•11mo ago
yep
meaniebeanie22
meaniebeanie22OP•11mo ago
another build fail, pycairo
Brody
Brody•11mo ago
ive updated this, try again please
meaniebeanie22
meaniebeanie22OP•11mo ago
still cant build wheels
Brody
Brody•11mo ago
alright time to abandon nixpacks, delete the nixpacks.toml file and then create a Dockerfile with this in it
FROM python:3.12.1-slim

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
pkg-config \
libcairo2-dev \
python3-dev

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . ./

CMD gunicorn tkdmanager.wsgi --log-file -
FROM python:3.12.1-slim

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
pkg-config \
libcairo2-dev \
python3-dev

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . ./

CMD gunicorn tkdmanager.wsgi --log-file -
meaniebeanie22
meaniebeanie22OP•11mo ago
GitHub
GitHub - meaniebeanie22/tkd-manager
Contribute to meaniebeanie22/tkd-manager development by creating an account on GitHub.
Brody
Brody•11mo ago
delete your Procfile while youre at it
meaniebeanie22
meaniebeanie22OP•11mo ago
deploying...
Brody
Brody•11mo ago
ah good then we have made it farther
meaniebeanie22
meaniebeanie22OP•11mo ago
sad gunicorn in deploy logs
usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: argument --error-logfile/--log-file: expected one argument
usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: argument --error-logfile/--log-file: expected one argument
Brody
Brody•11mo ago
updated, forgot a dash lol
meaniebeanie22
meaniebeanie22OP•11mo ago
back at it again when railway does environment variables are they all strings?
Brody
Brody•11mo ago
environment variables on any platform or even any OS will always be strings
meaniebeanie22
meaniebeanie22OP•11mo ago
beans
Brody
Brody•11mo ago
why is that beans? that doesnt stop you from setting numbers, the numbers will just be stored as a string
meaniebeanie22
meaniebeanie22OP•11mo ago
i had debug set to DEBUG = os.environ.get("DEBUG", True) so a string of "False" still == True
Brody
Brody•11mo ago
yeah you'd need to parse a string to a bool
meaniebeanie22
meaniebeanie22OP•11mo ago
ill just check if the string == "False" and if so then set DEBUG = False
Brody
Brody•11mo ago
that also works
meaniebeanie22
meaniebeanie22OP•11mo ago
oh and this
No description
meaniebeanie22
meaniebeanie22OP•11mo ago
ALLOWED_HOSTS = ["*"]
Brody
Brody•11mo ago
thats more so just a generic error, not all that related to deploying on railway, im sure there are a bunch of great tutorials for setting up csrf, that page even tells you a lot of what you need to know
meaniebeanie22
meaniebeanie22OP•11mo ago
was working a minute ago with py -3 manage.py runserver
Brody
Brody•11mo ago
thats a development server, absolutely not something you want to be running on railway
meaniebeanie22
meaniebeanie22OP•11mo ago
yeah I know not really sure how to fix all this though :D
Brody
Brody•11mo ago
i am not a python developer myself, so this is about all the advice i can offer you
meaniebeanie22
meaniebeanie22OP•11mo ago
ahh okay will try adding https:// *.railway.app to CSRF_TRUSTED_ORIGINS after that i have to figure out getting the database to work because atm it just sits in my repo with the other bits in a default config
Brody
Brody•11mo ago
yeah please dont use sqlite going forward
meaniebeanie22
meaniebeanie22OP•11mo ago
no volume or other db in the railway thing
Brody
Brody•11mo ago
postgres would be your best bet
meaniebeanie22
meaniebeanie22OP•11mo ago
it was the default and it just worked so I haven't needed to change until now where i wanted to see if i could get something to deploy
Brody
Brody•11mo ago
thats fair
meaniebeanie22
meaniebeanie22OP•11mo ago
okay some of the css is a tad dodgy but thats something I can probably fix if i want to add requirements i should just add them to requirements.txt right and everything should work?
Brody
Brody•11mo ago
yep that works all the same with the dockerfile I've provided
meaniebeanie22
meaniebeanie22OP•11mo ago
cheers mate!
Brody
Brody•11mo ago
Cheers!
meaniebeanie22
meaniebeanie22OP•11mo ago
Is there any way that I can take my freshly migrated postgres database and upload its contents to railway?
Brody
Brody•11mo ago
you have a local postgres database?
meaniebeanie22
meaniebeanie22OP•11mo ago
yes made one and migrated my sqlite3 one across
Brody
Brody•11mo ago
then you would want to look into pg_dump and pg_restore
meaniebeanie22
meaniebeanie22OP•11mo ago
thanks!
meaniebeanie22
meaniebeanie22OP•11mo ago
Database migrated (or at least i think so - all the tables i can understand) now the issue is i am apparently getting too many redirects
No description
meaniebeanie22
meaniebeanie22OP•11mo ago
fixed! add
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
to settings.py
Brody
Brody•11mo ago
I may not be a python developer but I'm still able to understand right and wrong, and that is indeed the right way to solve that issue
Want results from more Discord servers?
Add your server