a year ago
Hi, I'm trying to deploy my code which uses the pyzbar library, but upon deployment, it errors, saying ImportError: Unable to find zbar shared library
. I've researched this error, and apparently I need to install the packages libzbar-dev libzbar0
. I tried to do this with the startCommand in railway.json but it just doesn't work? I then saw this forum post () but it wasn't very helpful, as I'm new to using Nix.
Any help would be greatly appreciated, thank you.
0 Replies
startCommand in railway.json "startCommand": "sudo apt-get update && sudo apt-get install libzbar-dev libzbar0 zbar-tools -y && python3 [main.py](main.py)",
deploy logsHit:1 http://archive.ubuntu.com/ubuntu jammy InRelease Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Reading package lists... Reading package lists... Building dependency tree... Reading state information... libzbar-dev is already the newest version (0.23.92-4build2). libzbar0 is already the newest version (0.23.92-4build2). zbar-tools is already the newest version (0.23.92-4build2). 0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded. Traceback (most recent call last): File "main.py", line 5, in from moving_barcode import process_gif File "/app/moving_barcode.py", line 2, in from pyzbar.pyzbar import decode File "/opt/venv/lib/python3.8/site-packages/pyzbar/pyzbar.py", line 7, in from .wrapper import ( File "/opt/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 151, in zbar_version = zbar_function( File "/opt/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 148, in zbar_function return prototype((fname, load_libzbar())) File "/opt/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 127, in load_libzbar libzbar, dependencies = zbar_library.load() File "/opt/venv/lib/python3.8/site-packages/pyzbar/zbar_library.py", line 65, in load raise ImportError('Unable to find zbar shared library') ImportError: Unable to find zbar shared library
a year ago
can you provide a minimal reproducible example
a year ago
please remove the apt commands from the start command, you never want to to install packages like that during runtime
a year ago
the link you provided in your original post does contain a link to the docs page that does show you how to install apt packages during build, not that it would automatically fix it, but that would be at least the correct way to install packages
a year ago
when I'm back at my computer in several hours I will try to get your example working, in the mean time, please do remove the apt commands from the start command
i've removed the apt commands from the startcommand and put them in nixpacks.toml like this
[phases.setup] aptPkgs = ['libzbar-dev', 'libzbar0', 'zbar-tools']
altho it still says ImportError: Unable to find zbar shared library
a year ago
like 80% of the way there, but I doubt it's going to work anyway, while installing apt packages in the start command is something you should never do, it would technically work, so if it didn't actually work, then it's not going to work installing them during build either
a year ago
turns out I won't be able to get on my computer for another while since I now have to leave the house after waking up, try this nixpacks.toml file that I have not validated to work -
[phases.setup]
nixPkgs = ['...', 'zbar']
thanks for this, unfortunately it still does not work but i very much appreciate your help
a year ago
are you testing with your minimal example too?
a year ago
are you familiar with Dockerfiles?
a year ago
that's what I was gonna write for you
a year ago
I have never used docker either, I've only wrote dockerfiles
a year ago
I do
a year ago
but I'm quite far away from my computer right now
a year ago
will do
a year ago
hey @x finally back at my computer after being out all day, got the example app working with a Dockerfile and i have made a PR to the repo.
PR here
working example app here
the Dockerfile in the PR works for the example app, but it may be missing some other things that your actual app may need, but start by applying everything i did in the PR to your actual repo, such as deleteing the Procfile and Nixpacks.toml and making the changes to the railway.json file.
if the Dockerfile provided creates new errors i would be happy to work through them too.
hey brody, thank you very much for taking your time to help me with this, ive merged the pr and will work on making it work with the actual repo. sorry for my late reply, but yeah thank you so much. ill update you and let you know if it all goes well.
a year ago
sounds good!