Magic python lib isnt working.

dylzzz
HOBBY

a year ago

I will attach the full build logs below

0 Replies

dylzzz
HOBBY

a year ago

1b8eef65-7914-42b8-81ff-e5902b594bd8


dylzzz
HOBBY

a year ago


dylzzz
HOBBY

a year ago

It does work on my local pc just not when deploying


dylzzz
HOBBY

a year ago

I am also running the same python version on both railway and my pc


a year ago

what version of python do you use locally?


dylzzz
HOBBY

a year ago

Im using 3.12.0


a year ago

nixpacks doesnt support python 3.12 yet, so instead add 3.11 to a runtime.txt file


dylzzz
HOBBY

a year ago

Ohhh, good to know


dylzzz
HOBBY

a year ago

I just pushed with 3.11 now


dylzzz
HOBBY

a year ago

I still get the same error


dylzzz
HOBBY

a year ago


a year ago

python-magic-bin 0.4.14 if from 2017


dylzzz
HOBBY

a year ago

Is there a way to apt-get something?


dylzzz
HOBBY

a year ago

Ill try without making it 0.4.14


a year ago

yeah, but may i ask why?


a year ago

i would highly recommend using something pure python thats more up to date


dylzzz
HOBBY

a year 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


dylzzz
HOBBY

a year ago

I couldtn find anything


dylzzz
HOBBY

a year ago

because i had tried but there just wasnt anything up to date


dylzzz
HOBBY

a year ago

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


a year ago

the -bin version would include libmagic1


a year ago

im now thinking python-magic-bin is not compatible with python 3.8+


dylzzz
HOBBY

a year ago

I dont know if i even have a python version that old on my local pc


dylzzz
HOBBY

a year ago

And it does work on my local pc


dylzzz
HOBBY

a year ago

I will check again to make sure


dylzzz
HOBBY

a year ago

Yeha it works on my pc


dylzzz
HOBBY

a year ago

using python 3.12


a year ago

its already installed, so of course it will work lol


dylzzz
HOBBY

a year ago

Oh wait


dylzzz
HOBBY

a year ago

im tired lmao


dylzzz
HOBBY

a year ago

It does install on my pc


dylzzz
HOBBY

a year ago

It does install on my localpc


a year ago

its already installed


dylzzz
HOBBY

a year ago

I just tried uninstalling


dylzzz
HOBBY

a year ago

and installing agian with --no-cache-dir


dylzzz
HOBBY

a year ago

and it did work


a year ago

what os are you using?


dylzzz
HOBBY

a year ago

Windows 10


dylzzz
HOBBY

a year ago

so its obv a lot different then ubuntu but idk


a year ago

might not support ubuntu


dylzzz
HOBBY

a year ago

Im guessing not


dylzzz
HOBBY

a year ago

but i did read that python-magic can be installed with apt-get install


dylzzz
HOBBY

a year ago

on some random website


dylzzz
HOBBY

a year ago

so would i be able to test that? or is that not doable?


dylzzz
HOBBY

a year ago

Oh it seems like its for python 2.7 though so nevermind


dylzzz
HOBBY

a year ago

Im not very good with linux so I dont know


a year ago

use this
and then place this nixpacks.toml file in your project -

[phases.setup]
  aptPkgs = ['...', 'libmagic1']

dylzzz
HOBBY

a year ago

Okay let me give that a try


dylzzz
HOBBY

a year ago

Im getting an Import error now, ```
File "/app/Routes/fileUploads.py", line 10, in

import magic

File "/opt/venv/lib/python3.11/site-packages/magic/init.py", line 209, in

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```


a year ago

build logs please


dylzzz
HOBBY

a year ago


a year ago

is this a web app of some kind?


dylzzz
HOBBY

a year ago

Yeah


dylzzz
HOBBY

a year ago

Im using the magic lib for a file uplaoder


a year ago

flask? fastapi?


dylzzz
HOBBY

a year ago

fastapi


a year ago

why arent you using gunicorn?


dylzzz
HOBBY

a year ago

I wish i had an answer lol


dylzzz
HOBBY

a year ago

pretty much got lazy and im jsut debugging atm


dylzzz
HOBBY

a year ago

I will swap to it though


dylzzz
HOBBY

a year ago

Is gunicorn like way better than uvicorn?


dylzzz
HOBBY

a year ago

I havent looked into that much at all to be honest


a year ago

haha im tired too, i meant uvicorn


dylzzz
HOBBY

a year ago

ohh


dylzzz
HOBBY

a year ago

I just do it in my python code


dylzzz
HOBBY

a year ago

Because of my debugging on my pc


dylzzz
HOBBY

a year ago

it was jsut quicker to run it lol


dylzzz
HOBBY

a year ago

so pretty much just because im lazy


a year ago

the fastapi constructor is named app right?


dylzzz
HOBBY

a year ago

Yeah


dylzzz
HOBBY

a year ago

1225689219540975600


dylzzz
HOBBY

a year ago

Heres how i start it


dylzzz
HOBBY

a year ago

Would it be better to start it using the start command, or is this just fine?


a year 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

(you can delete the nixpacks.toml file)


dylzzz
HOBBY

a year ago

Okay, ive never toucher dockerfiles so i dont knwo them well. What do i name the file? Just Dockerfile?


a year ago

correct


dylzzz
HOBBY

a year ago

alright


a year ago

as you can see, its just a set of commands that setup the project, super simple stuff


dylzzz
HOBBY

a year ago

Yeah they seem pretty helpful


dylzzz
HOBBY

a year ago

maybe ill look into them some more


a year ago

not as finicky as nixpacks


dylzzz
HOBBY

a year ago

It started


dylzzz
HOBBY

a year ago

Let me test it out but it should work


dylzzz
HOBBY

a year ago

The code ran so that seems like a good sign to me


dylzzz
HOBBY

a year ago

Thank you!!


dylzzz
HOBBY

a year ago

Ive been trying to figure that out for days now lol


a year ago

no problem!


dylzzz
HOBBY

a year ago

Have a good night!


a year ago

Dockerfiles are always the answer


a year ago

you too!!


dylzzz
HOBBY

a year ago

Will use them in the future


Magic python lib isnt working. - Railway Help Station