Magic python lib isnt working.

dylzzzHOBBY

a year ago

I will attach the full build logs below

0 Replies

dylzzzHOBBY

a year ago

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


dylzzzHOBBY

a year ago


dylzzzHOBBY

a year ago

It does work on my local pc just not when deploying


dylzzzHOBBY

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?


dylzzzHOBBY

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


dylzzzHOBBY

a year ago

Ohhh, good to know


dylzzzHOBBY

a year ago

I just pushed with 3.11 now


dylzzzHOBBY

a year ago

I still get the same error


dylzzzHOBBY

a year ago


a year ago

python-magic-bin 0.4.14 if from 2017


dylzzzHOBBY

a year ago

Is there a way to apt-get something?


dylzzzHOBBY

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


dylzzzHOBBY

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


dylzzzHOBBY

a year ago

I couldtn find anything


dylzzzHOBBY

a year ago

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


dylzzzHOBBY

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+


dylzzzHOBBY

a year ago

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


dylzzzHOBBY

a year ago

And it does work on my local pc


dylzzzHOBBY

a year ago

I will check again to make sure


dylzzzHOBBY

a year ago

Yeha it works on my pc


dylzzzHOBBY

a year ago

using python 3.12


a year ago

its already installed, so of course it will work lol


dylzzzHOBBY

a year ago

Oh wait


dylzzzHOBBY

a year ago

im tired lmao


dylzzzHOBBY

a year ago

It does install on my pc


dylzzzHOBBY

a year ago

It does install on my localpc


a year ago

its already installed


dylzzzHOBBY

a year ago

I just tried uninstalling


dylzzzHOBBY

a year ago

and installing agian with --no-cache-dir


dylzzzHOBBY

a year ago

and it did work


a year ago

what os are you using?


dylzzzHOBBY

a year ago

Windows 10


dylzzzHOBBY

a year ago

so its obv a lot different then ubuntu but idk


a year ago

might not support ubuntu


dylzzzHOBBY

a year ago

Im guessing not


dylzzzHOBBY

a year ago

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


dylzzzHOBBY

a year ago

on some random website


dylzzzHOBBY

a year ago

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


dylzzzHOBBY

a year ago

Oh it seems like its for python 2.7 though so nevermind


dylzzzHOBBY

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']

dylzzzHOBBY

a year ago

Okay let me give that a try


dylzzzHOBBY

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


dylzzzHOBBY

a year ago


a year ago

is this a web app of some kind?


dylzzzHOBBY

a year ago

Yeah


dylzzzHOBBY

a year ago

Im using the magic lib for a file uplaoder


a year ago

flask? fastapi?


dylzzzHOBBY

a year ago

fastapi


a year ago

why arent you using gunicorn?


dylzzzHOBBY

a year ago

I wish i had an answer lol


dylzzzHOBBY

a year ago

pretty much got lazy and im jsut debugging atm


dylzzzHOBBY

a year ago

I will swap to it though


dylzzzHOBBY

a year ago

Is gunicorn like way better than uvicorn?


dylzzzHOBBY

a year ago

I havent looked into that much at all to be honest


a year ago

haha im tired too, i meant uvicorn


dylzzzHOBBY

a year ago

ohh


dylzzzHOBBY

a year ago

I just do it in my python code


dylzzzHOBBY

a year ago

Because of my debugging on my pc


dylzzzHOBBY

a year ago

it was jsut quicker to run it lol


dylzzzHOBBY

a year ago

so pretty much just because im lazy


a year ago

the fastapi constructor is named app right?


dylzzzHOBBY

a year ago

Yeah


dylzzzHOBBY

a year ago

1225689219540975600


dylzzzHOBBY

a year ago

Heres how i start it


dylzzzHOBBY

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)


dylzzzHOBBY

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


dylzzzHOBBY

a year ago

alright


a year ago

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


dylzzzHOBBY

a year ago

Yeah they seem pretty helpful


dylzzzHOBBY

a year ago

maybe ill look into them some more


a year ago

not as finicky as nixpacks


dylzzzHOBBY

a year ago

It started


dylzzzHOBBY

a year ago

Let me test it out but it should work


dylzzzHOBBY

a year ago

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


dylzzzHOBBY

a year ago

Thank you!!


dylzzzHOBBY

a year ago

Ive been trying to figure that out for days now lol


a year ago

no problem!


dylzzzHOBBY

a year ago

Have a good night!


a year ago

Dockerfiles are always the answer


a year ago

you too!!


dylzzzHOBBY

a year ago

Will use them in the future


Magic python lib isnt working. - Railway Help Station