1
1

More than 3 years have passed since last update.

Heroku で pyzbar を使う

Posted at

はじめに

pythonのpyzbarを使ってQRコードを読み取るアプリをHerokuでデプロイしようとしていたところ、
import Errorでハマったので備忘録

環境

  • Heroku
  • python 3.9.1
  • pyzbar 0.1.8

概要

pyzbarはzbarのラッパーのためライブラリが必要。
ubuntuではlibzbar-devをインストールすれば使えるよう。
Windowsでやっていたから気付かなかった。

1. Buildpackを追加

Herokuからheroku-buildpack-aptというbuildpackが公開されている。
デプロイ時にAptfileに書かれているパッケージをインストールしてくれる。

また、heroku-buildpack-zbarというbuildpackもあるよう。
こちらはデプロイ時にzbarをインストールしてくれるらしいが未確認。

今回はaptを使っていく。

2. Aptfileを作成

Aptfile
libzbar-dev

これだけでデプロイ時に勝手にやってくれる

3. デプロイ

通常通りにデプロイすればこんな感じでインストールしてくれる

git.log
remote: -----> Apt app detected        
remote: -----> Detected Aptfile or Stack changes, flushing cache        
remote: -----> Updating apt caches        
remote:        Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease        
remote:        Hit:2 http://apt.postgresql.org/pub/repos/apt focal-pgdg InRelease        
remote:        Hit:3 http://archive.ubuntu.com/ubuntu focal-security InRelease        
remote:        Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease        
remote:        Reading package lists...        
remote: -----> Fetching .debs for libzbar-dev        
remote:        Reading package lists...        
remote:        Building dependency tree...        
remote:        The following additional packages will be installed:        
remote:          libmagick++-6-headers libmagick++-6.q16-8 libmagick++-6.q16-dev        
remote:          libmagick++-dev libv4l-0 libv4lconvert0 libzbar0        
remote:        The following NEW packages will be installed:        
remote:          libmagick++-6-headers libmagick++-6.q16-8 libmagick++-6.q16-dev        
remote:          libmagick++-dev libv4l-0 libv4lconvert0 libzbar-dev libzbar0        
remote:        0 upgraded, 8 newly installed, 0 to remove and 9 not upgraded.

ハマりポイント

その1

Herokuではsudoもaptも使えない。
だからheroku run bashでターミナルに入ってもできない。

その2

インストールするパッケージはlibzbar0ではなくlibzbar-dev。
最初に見た記事ではlibzbar0だったためここで躓いた。

Git push時に変更がなくてもPushしたい

git commit --allow-empty -m "commit without change"
git push

これで空のコミットを生成できる。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1