Sunday, June 5, 2022

[SOLVED] Why don't these apt-packages behave the same on Ubuntu and Heroku?

Issue

I want to use ZBar from Python on Heroku. On a regular Ubuntu 14.04 server I can run either

sudo apt-get install python-qrtools

-- OR --

sudo apt-get install zbar-tools
sudo apt-get install libzbar-dev
sudo apt-get install python-zbar

After either the first, or the last three I can do an import zbar from Python. So using heroku-buildpack-apt (in combination with heroku-buildpack-multi) I tried both options. In both cases it seems to install everything correctly without errors (see installation logs below), but trying it on a python command line always yields:

>>> import zbar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named zbar

Seeing that the Heroku logs (below) list the Linux distro as Ubuntu Trusty (=14.04) I don't see why it does work on my own 14.04 install, but doesn't work on Heroku.

Does anybody know why this doesn't work and how I can install the needed packages on Heroku? All tips are welcome!

Heroku install logs when trying to install python-qrtools:

remote: =====> Downloading Buildpack: https://github.com/ddollar/heroku-buildpack-apt
remote: =====> Detected Framework: Apt
remote: -----> Updating apt caches
remote:        Ign http://archive.ubuntu.com trusty InRelease
remote:        Ign http://archive.ubuntu.com trusty-security InRelease
remote:        Ign http://archive.ubuntu.com trusty-updates InRelease
remote:        Hit http://archive.ubuntu.com trusty Release.gpg
remote:        Hit http://archive.ubuntu.com trusty-security Release.gpg
remote:        Hit http://archive.ubuntu.com trusty-updates Release.gpg
remote:        Hit http://archive.ubuntu.com trusty Release
remote:        Hit http://archive.ubuntu.com trusty-security Release
remote:        Hit http://archive.ubuntu.com trusty-updates Release
remote:        Hit http://archive.ubuntu.com trusty/main amd64 Packages
remote:        Hit http://archive.ubuntu.com trusty/universe amd64 Packages
remote:        Hit http://archive.ubuntu.com trusty/main Translation-en
remote:        Hit http://archive.ubuntu.com trusty/universe Translation-en
remote:        Hit http://archive.ubuntu.com trusty-security/main amd64 Packages
remote:        Hit http://archive.ubuntu.com trusty-security/main Translation-en
remote:        Hit http://archive.ubuntu.com trusty-updates/main amd64 Packages
remote:        Hit http://archive.ubuntu.com trusty-updates/main Translation-en
remote:        Ign http://archive.ubuntu.com trusty/main Translation-en_US
remote:        Ign http://archive.ubuntu.com trusty/universe Translation-en_US
remote:        Reading package lists...
remote: -----> Fetching .debs for python-qrtools
remote:        Reading package lists...
remote:        Building dependency tree...
remote:        The following extra packages will be installed:
remote:          libqrencode3 libv4l-0 libv4lconvert0 libwebp5 libwebpmux1 libzbar0
remote:          python-imaging python-pil python-zbar qrencode
remote:        Suggested packages:
remote:          python-pil-doc python-pil-dbg
remote:        The following NEW packages will be installed:
remote:          libqrencode3 libv4l-0 libv4lconvert0 libwebp5 libwebpmux1 libzbar0
remote:          python-imaging python-pil python-qrtools python-zbar qrencode
remote:        0 upgraded, 11 newly installed, 0 to remove and 81 not upgraded.
remote:        Need to get 0 B/721 kB of archives.
remote:        After this operation, 2,724 kB of additional disk space will be used.
remote:        Download complete and in download only mode
remote: -----> Installing libqrencode3_3.4.2-1_amd64.deb
remote: -----> Installing libv4l-0_1.0.1-1_amd64.deb
remote: -----> Installing libv4lconvert0_1.0.1-1_amd64.deb
remote: -----> Installing libwebp5_0.4.0-4_amd64.deb
remote: -----> Installing libwebpmux1_0.4.0-4_amd64.deb
remote: -----> Installing libzbar0_0.10+doc-9build1_amd64.deb
remote: -----> Installing python-imaging_2.3.0-1ubuntu3_all.deb
remote: -----> Installing python-pil_2.3.0-1ubuntu3_amd64.deb
remote: -----> Installing python-qrtools_1.4~bzr16-1ubuntu1_all.deb
remote: -----> Installing python-zbar_0.10+doc-9build1_amd64.deb
remote: -----> Installing qrencode_3.4.2-1_amd64.deb
remote: -----> Writing profile script
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-python.git
remote: =====> Detected Framework: Python
remote: -----> Installing dependencies with pip
remote:        Cleaning up...
remote:
remote: Using release configuration from last framework (Python).
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 39.4MB
remote: -----> Launching... done, v22
remote:        https://mysterious-man-1234.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.

Heroku install logs when trying to install zbar-tools, libzbar-dev and python-zbar:

remote: =====> Downloading Buildpack: https://github.com/ddollar/heroku-buildpack-apt
remote: =====> Detected Framework: Apt
remote: -----> Updating apt caches
remote:        Ign http://archive.ubuntu.com trusty InRelease
remote:        Ign http://archive.ubuntu.com trusty-security InRelease
remote:        Ign http://archive.ubuntu.com trusty-updates InRelease
remote:        Hit http://archive.ubuntu.com trusty Release.gpg
remote:        Get:1 http://archive.ubuntu.com trusty-security Release.gpg [933 B]
remote:        Get:2 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]
remote:        Hit http://archive.ubuntu.com trusty Release
remote:        Get:3 http://archive.ubuntu.com trusty-security Release [62.0 kB]
remote:        Get:4 http://archive.ubuntu.com trusty-updates Release [62.0 kB]
remote:        Hit http://archive.ubuntu.com trusty/main amd64 Packages
remote:        Hit http://archive.ubuntu.com trusty/universe amd64 Packages
remote:        Hit http://archive.ubuntu.com trusty/main Translation-en
remote:        Hit http://archive.ubuntu.com trusty/universe Translation-en
remote:        Get:5 http://archive.ubuntu.com trusty-security/main amd64 Packages [181 kB]
remote:        Hit http://archive.ubuntu.com trusty-security/main Translation-en
remote:        Get:6 http://archive.ubuntu.com trusty-updates/main amd64 Packages [384 kB]
remote:        Hit http://archive.ubuntu.com trusty-updates/main Translation-en
remote:        Ign http://archive.ubuntu.com trusty/main Translation-en_US
remote:        Ign http://archive.ubuntu.com trusty/universe Translation-en_US
remote:        Fetched 691 kB in 3s (219 kB/s)
remote:        Reading package lists...
remote: -----> Fetching .debs for zbar-tools
remote:        Reading package lists...
remote:        Building dependency tree...
remote:        The following extra packages will be installed:
remote:          libv4l-0 libv4lconvert0 libzbar0
remote:        The following NEW packages will be installed:
remote:          libv4l-0 libv4lconvert0 libzbar0 zbar-tools
remote:        0 upgraded, 4 newly installed, 0 to remove and 81 not upgraded.
remote:        Need to get 0 B/231 kB of archives.
remote:        After this operation, 861 kB of additional disk space will be used.
remote:        Download complete and in download only mode
remote: -----> Fetching .debs for libzbar-dev
remote:        Reading package lists...
remote:        Building dependency tree...
remote:        The following extra packages will be installed:
remote:          libmagick++-dev libmagick++5 libv4l-0 libv4lconvert0 libzbar0
remote:        The following NEW packages will be installed:
remote:          libmagick++-dev libmagick++5 libv4l-0 libv4lconvert0 libzbar-dev libzbar0
remote:        0 upgraded, 6 newly installed, 0 to remove and 81 not upgraded.
remote:        Need to get 0 B/563 kB of archives.
remote:        After this operation, 2,980 kB of additional disk space will be used.
remote:        Download complete and in download only mode
remote: -----> Fetching .debs for python-zbar
remote:        Reading package lists...
remote:        Building dependency tree...
remote:        The following extra packages will be installed:
remote:          libv4l-0 libv4lconvert0 libzbar0
remote:        The following NEW packages will be installed:
remote:          libv4l-0 libv4lconvert0 libzbar0 python-zbar
remote:        0 upgraded, 4 newly installed, 0 to remove and 81 not upgraded.
remote:        Need to get 0 B/225 kB of archives.
remote:        After this operation, 873 kB of additional disk space will be used.
remote:        Download complete and in download only mode
remote: -----> Installing libmagick++5_8%3a6.7.7.10-6ubuntu3_amd64.deb
remote: -----> Installing libmagick++-dev_8%3a6.7.7.10-6ubuntu3_amd64.deb
remote: -----> Installing libqrencode3_3.4.2-1_amd64.deb
remote: -----> Installing libv4l-0_1.0.1-1_amd64.deb
remote: -----> Installing libv4lconvert0_1.0.1-1_amd64.deb
remote: -----> Installing libwebp5_0.4.0-4_amd64.deb
remote: -----> Installing libwebpmux1_0.4.0-4_amd64.deb
remote: -----> Installing libzbar0_0.10+doc-9build1_amd64.deb
remote: -----> Installing libzbar-dev_0.10+doc-9build1_amd64.deb
remote: -----> Installing python-imaging_2.3.0-1ubuntu3_all.deb
remote: -----> Installing python-pil_2.3.0-1ubuntu3_amd64.deb
remote: -----> Installing python-qrtools_1.4~bzr16-1ubuntu1_all.deb
remote: -----> Installing python-zbar_0.10+doc-9build1_amd64.deb
remote: -----> Installing qrencode_3.4.2-1_amd64.deb
remote: -----> Installing zbar-tools_0.10+doc-9build1_amd64.deb
remote: -----> Writing profile script
remote: Using release configuration from last framework (Apt).
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 39.8MB
remote: -----> Launching... done, v24
remote:        https://mystery-man-1234.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.

Solution

With the amazing help of @PadraicCunningham I managed to find the solution. The problem turned out to be that heroku-buildpack-apt installs things in a newly created folder /app/.apt/ which was not in the PYTHONPATH.

So I added the relevant folder to my PYTHONPATH on heroku as follows:

heroku config:add PYTHONPATH=/app/.apt/usr/lib/python2.7/dist-packages/

This solved the issue. Again a big thanks to PadraicCunningham for helping me to find this issue!



Answered By - kramer65
Answer Checked By - Marilyn (WPSolving Volunteer)