R
Railway•6mo ago
xeny

pyzbar library

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 (https://www.answeroverflow.com/m/1051264145758093362) but it wasn't very helpful, as I'm new to using Nix. Any help would be greatly appreciated, thank you.
Solution:
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 https://github.com/1x6/pyzbar-error/pull/1 working example app here https://zbar.up.railway.app/ 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....
Jump to solution
26 Replies
Percy
Percy•6mo ago
Project ID: 52094dae-9587-400c-9449-0c0ac30d2014
xeny
xeny•6mo ago
52094dae-9587-400c-9449-0c0ac30d2014 startCommand in railway.json "startCommand": "sudo apt-get update && sudo apt-get install libzbar-dev libzbar0 zbar-tools -y && python3 main.py", deploy logs
Hit: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 <module>
from moving_barcode import process_gif
File "/app/moving_barcode.py", line 2, in <module>
from pyzbar.pyzbar import decode
File "/opt/venv/lib/python3.8/site-packages/pyzbar/pyzbar.py", line 7, in <module>
from .wrapper import (
File "/opt/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 151, in <module>
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
Hit: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 <module>
from moving_barcode import process_gif
File "/app/moving_barcode.py", line 2, in <module>
from pyzbar.pyzbar import decode
File "/opt/venv/lib/python3.8/site-packages/pyzbar/pyzbar.py", line 7, in <module>
from .wrapper import (
File "/opt/venv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 151, in <module>
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
Brody
Brody•6mo ago
can you provide a minimal reproducible example
xeny
xeny•6mo ago
yep
xeny
xeny•6mo ago
GitHub
GitHub - 1x6/pyzbar-error
Contribute to 1x6/pyzbar-error development by creating an account on GitHub.
xeny
xeny•6mo ago
deploy this and it should reproduce the error
Brody
Brody•6mo ago
please remove the apt commands from the start command, you never want to to install packages like that during runtime
xeny
xeny•6mo ago
oh okay, how would you suggest i do it please
Brody
Brody•6mo 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 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
xeny
xeny•6mo ago
i see, thank you. i'll try use that much appreciated, will do 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']
[phases.setup]
aptPkgs = ['libzbar-dev', 'libzbar0', 'zbar-tools']
altho it still says ImportError: Unable to find zbar shared library
Brody
Brody•6mo 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 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']
[phases.setup]
nixPkgs = ['...', 'zbar']
xeny
xeny•6mo ago
thanks for this, unfortunately it still does not work but i very much appreciate your help thats a fair point 😭
Brody
Brody•6mo ago
are you testing with your minimal example too?
xeny
xeny•6mo ago
yeah i've been working on the minimal one all this time
Brody
Brody•6mo ago
are you familiar with Dockerfiles?
Want results from more Discord servers?
Add your server