R
Railway8mo ago
DylZ

Magic python lib isnt working.

I will attach the full build logs below
Solution:
nixpacks is being difficult, we are moving to a Dockerfile, add this as a Dockerfile to your project - ```dockerfile FROM python:3.12 ENV PYTHONUNBUFFERED=1...
Jump to solution
51 Replies
Percy
Percy8mo ago
Project ID: 1b8eef65-7914-42b8-81ff-e5902b594bd8
DylZ
DylZOP8mo ago
1b8eef65-7914-42b8-81ff-e5902b594bd8
DylZ
DylZOP8mo ago
It does work on my local pc just not when deploying I am also running the same python version on both railway and my pc
Brody
Brody8mo ago
what version of python do you use locally?
DylZ
DylZOP8mo ago
Im using 3.12.0
Brody
Brody8mo ago
nixpacks doesnt support python 3.12 yet, so instead add 3.11 to a runtime.txt file
DylZ
DylZOP8mo ago
Ohhh, good to know I just pushed with 3.11 now I still get the same error
Brody
Brody8mo ago
python-magic-bin 0.4.14 if from 2017
DylZ
DylZOP8mo ago
Is there a way to apt-get something? Ill try without making it 0.4.14
Brody
Brody8mo ago
yeah, but may i ask why? i would highly recommend using something pure python thats more up to date
DylZ
DylZOP8mo ago
On the python-magic github it says on Debian/Ubuntu to use sudo apt-get install libmagic1, i just didnt know if i could apt-get something on railway so i was trying to do it without using it I couldtn find anything because i had tried but there just wasnt anything up to date I am using something from 7 years ago right now and it is just too outdated so I was hoping to get something a little newer
Brody
Brody8mo ago
the -bin version would include libmagic1 im now thinking python-magic-bin is not compatible with python 3.8+
DylZ
DylZOP8mo ago
I dont know if i even have a python version that old on my local pc And it does work on my local pc I will check again to make sure Yeha it works on my pc using python 3.12
Brody
Brody8mo ago
its already installed, so of course it will work lol
DylZ
DylZOP8mo ago
Oh wait im tired lmao It does install on my localpc
Brody
Brody8mo ago
its already installed
DylZ
DylZOP8mo ago
I just tried uninstalling and installing agian with --no-cache-dir and it did work
Brody
Brody8mo ago
what os are you using?
DylZ
DylZOP8mo ago
Windows 10 so its obv a lot different then ubuntu but idk
Brody
Brody8mo ago
might not support ubuntu
DylZ
DylZOP8mo ago
Im guessing not but i did read that python-magic can be installed with apt-get install on some random website so would i be able to test that? or is that not doable? Oh it seems like its for python 2.7 though so nevermind Im not very good with linux so I dont know
Brody
Brody8mo ago
use this https://pypi.org/project/python-magic/ and then place this nixpacks.toml file in your project -
[phases.setup]
aptPkgs = ['...', 'libmagic1']
[phases.setup]
aptPkgs = ['...', 'libmagic1']
DylZ
DylZOP8mo ago
Okay let me give that a try Im getting an Import error now,
File "/app/Routes/fileUploads.py", line 10, in <module>

import magic

File "/opt/venv/lib/python3.11/site-packages/magic/__init__.py", line 209, in <module>

libmagic = loader.load_lib()

^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/magic/loader.py", line 49, in load_lib

raise ImportError('failed to find libmagic. Check your installation')

ImportError: failed to find libmagic. Check your installation
File "/app/Routes/fileUploads.py", line 10, in <module>

import magic

File "/opt/venv/lib/python3.11/site-packages/magic/__init__.py", line 209, in <module>

libmagic = loader.load_lib()

^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/magic/loader.py", line 49, in load_lib

raise ImportError('failed to find libmagic. Check your installation')

ImportError: failed to find libmagic. Check your installation
Brody
Brody8mo ago
build logs please
Brody
Brody8mo ago
is this a web app of some kind?
DylZ
DylZOP8mo ago
Yeah Im using the magic lib for a file uplaoder
Brody
Brody8mo ago
flask? fastapi?
DylZ
DylZOP8mo ago
fastapi
Brody
Brody8mo ago
why arent you using gunicorn?
DylZ
DylZOP8mo ago
I wish i had an answer lol pretty much got lazy and im jsut debugging atm I will swap to it though Is gunicorn like way better than uvicorn? I havent looked into that much at all to be honest
Brody
Brody8mo ago
haha im tired too, i meant uvicorn
DylZ
DylZOP8mo ago
ohh I just do it in my python code Because of my debugging on my pc it was jsut quicker to run it lol so pretty much just because im lazy
Brody
Brody8mo ago
the fastapi constructor is named app right?
DylZ
DylZOP8mo ago
Yeah
DylZ
DylZOP8mo ago
No description
DylZ
DylZOP8mo ago
Heres how i start it Would it be better to start it using the start command, or is this just fine?
Solution
Brody
Brody8mo ago
nixpacks is being difficult, we are moving to a Dockerfile, add this as a Dockerfile to your project -
FROM python:3.12

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libmagic1

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . ./

CMD uvicorn main:app --host 0.0.0.0 --port $PORT
FROM python:3.12

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libmagic1

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . ./

CMD uvicorn main:app --host 0.0.0.0 --port $PORT
(you can delete the nixpacks.toml file)
DylZ
DylZOP8mo ago
Okay, ive never toucher dockerfiles so i dont knwo them well. What do i name the file? Just Dockerfile?
Brody
Brody8mo ago
correct
DylZ
DylZOP8mo ago
alright
Brody
Brody8mo ago
as you can see, its just a set of commands that setup the project, super simple stuff
DylZ
DylZOP8mo ago
Yeah they seem pretty helpful maybe ill look into them some more
Brody
Brody8mo ago
not as finicky as nixpacks
DylZ
DylZOP8mo ago
It started Let me test it out but it should work The code ran so that seems like a good sign to me Thank you!! Ive been trying to figure that out for days now lol
Brody
Brody8mo ago
no problem!
DylZ
DylZOP8mo ago
Have a good night!
Brody
Brody8mo ago
Dockerfiles are always the answer you too!!
DylZ
DylZOP8mo ago
Will use them in the future
Want results from more Discord servers?
Add your server