heroku cannot install zbar - python

I have a Django application which uses zbar for barcode recognition.
It works fine on my developer machine but when i tried to deploy it to Heroku my commit was rejected with the following message:
Installing collected packages: zbar
Running setup.py install for zbar
building 'zbar' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/app/.heroku/python/include/python2.7 -c zbarmodule.c -o build/temp.linux-x86_64-2.7/zbarmodule.o
In file included from zbarmodule.c:24:
zbarmodule.h:26:18: error: zbar.h: No such file or directory
In file included from zbarmodule.c:24:
/*many "undeclared" errors*/
! Push rejected, failed to compile Python app
pip install zbar works fine on my computer.
And i filled requirements.txt
cat requirements.txt
Django==1.5.5
PIL==1.1.7
dj-database-url==0.2.2
dj-static==0.0.5
django-toolbelt==0.0.1
gunicorn==18.0
psycopg2==2.5.1
static==0.4
wsgiref==0.1.2
zbar==0.10
Can anyone help me?
PS Sorry for my writing mistakes. English in not my native language.

Check this way:
Create heroku app
Create next files
app.py
from pyzbar.pyzbar import decode
Procfile
main: python app.py
requirements.txt
pyzbar==0.1.8
Aptfile
libzbar-dev
And add next buildpacks:
https://github.com/heroku/heroku-buildpack-apt.git
heroku/python
Push files and run app on heroku
source: https://github.com/NaturalHistoryMuseum/pyzbar/issues/23#issuecomment-615893637

the zbar python package is just a wrapper.
You need to use heroku buildpacks.
https://elements.heroku.com/buildpacks/generalui/heroku-buildpack-zbar
this buildpack will install zbar on build
alternatively, you can also use this:
https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-apt
and then include file called Aptfile in the root of your project
libzbar-dev
it will install libzbar-dev using apt-get so when pip install zbar runs, zbar will exist.
edit: include apt-get method

Related

Problems installing snappy on python on Alpine Linux

When i am trying to install Snappy on alpine linux using:
pip install snappy
I am getting the following error when it tries to install a required package called cypari.
I installed snappy from "apk add snappy"
gcc -fno-strict-aliasing -Os -fomit-frame-pointer -g -DNDEBUG -Os -fomit-frame-pointer -g -fPIC -Ilibcache/pari64/include -I/usr/include/python2.7 -c cypari_src/_pari.c -o build/temp.linux-x86_64-2.7/cypari_src/_pari.o
In file included from cypari_src/_pari.c:460:0:
cypari_src/implementation.c:47:22: fatal error: execinfo.h: No such file or directory
#include <execinfo.h>
I solved this problem by running apk add libexecinfo libexecinfo-dev
Then using apk add snappy
Then using pip install python-snappy
if you use pip install snappy it installs a completely different library which is this
Combining previous answers, this minimal Dockerfile works for me
FROM python:3.6-alpine
RUN apk add --no-cache g++ snappy-dev && \
pip install --no-cache-dir --ignore-installed python-snappy
Installing execinfo-dev suffice, since execinfo.h is in that package.
You can check it here:
http://pkgs.alpinelinux.org/contents?file=execinfo.h&path=&name=&branch=&repo=&arch=
apk add snappy
will install the package, so you don't need to:
pip install snappy
To expand on the answer from #dwardu, I also had to install the snappy-dev package. That fixed this error I was getting from pip install:
snappy-c.h: No such file or directory

#include <zbar.h> 1 error generated when running pip install zbar

I'm trying to run pip install zbar and for some reason I can't seem to find an answer to solve this dependency issue. Any help would be extremely appreciated. See traceback below:
Downloading/unpacking zbar
Downloading zbar-0.10.tar.bz2
Running setup.py
egg_info for package zbar
Installing collected packages: zbar
Running setup.py install for zbar
building 'zbar' extension
clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c zbarmodule.c -o build/temp.macosx-10.9-x86_64-2.7/zbarmodule.o
In file included from zbarmodule.c:24:
./zbarmodule.h:26:10: fatal error: 'zbar.h' file not found
#include <zbar.h>
^
1 error generated.
error: command 'clang' failed with exit status 1
running install
running build
running build_ext
building 'zbar' extension
creating build
creating build/temp.macosx-10.9-x86_64-2.7
clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c zbarmodule.c -o build/temp.macosx-10.9-x86_64-2.7/zbarmodule.o
In file included from zbarmodule.c:24:
./zbarmodule.h:26:10: fatal error: 'zbar.h' file not found
include <zbar.h>
^
1 error generated.
error: command 'clang' failed with exit status 1
In my case I was running Ubuntu and had to install libzbar-dev package:
sudo apt-get install libzbar-dev
$ brew install zbar
and after that
$ pip install zbar
The header files will then be found (zbar.h)
Encountered this problem again after 2 years... this is what worked for me
LDFLAGS=-L/usr/local/lib/ CPATH=/usr/local/include/ pip install zbar
In case others run into this issue aren't able to use pip to install zbar for python:
Install zbar: brew install zbar
Install PIL: brew install pillow
Download zbar source: https://pypi.python.org/pypi/zbar
Unzip zbar: tar -xjvf zbar-0.10.tar.bz2
Install: python setup.py install --user
I encountered this issue recently while attempting to launch a service locally from Mac OS in a virtual environment, that imports zbar in the python application. The service was still running python2.7.
Having the service running in a virtual environment I was unwilling to attempt anything that required global system changes.
I solved it by having to install zbar through Homebrew (globally). Then exporting flags or implicit rules used in the C compiling "recipe" to the virtual environment. Finally I installed a similar library to the zbar dependancy in the virtual environment.
$ brew install zbar
Then when sourced in the virtual environment I do the following to change the implicit rules in the c compilation recipe:
$ export LDFLAGS="-L$(brew --prefix zbar)/lib"
$ export CFLAGS="-I$(brew --prefix zbar)/include"
Finally I install a light version of zbar inside the venv:
$ pip install zbarlight
After the above, with the additional dependancy of pyzbar below included in my requirements.txt I am able to import zbar with python2.7 in the virtual environment.
pyzbar==0.1.7
Testing the import in the virtual environment:
$ python
>>> import zbar
>>>
Hope this helps someone in the future. I struggled quite a bit in getting this to work and resources regarding zbar are fairly scarce.

install a python library, specifically pycurl, on my heroku box (Rails application)

So I built this rails application locally and deployed it via Heroku. There is this important python script I rely on that heavily uses the pycurl library. My script is able to run locally because I was able to easily download and install pycurl on my local machine. The problem is pycurl is not installed remotely on Heroku, and I cannot seem to figure out how to install pycurl so that Heroku can run my python script. I downloaded setuptools, as well as the pycurl tar file in my rails app and tried to ssh into heroku and run something like python setyp.py install, or pip install pycurl, however, none of these commands will run because I do not and cannot have write access to this directory: /usr/local/lib/python2.7/site-packages/ on heroku (you also cannot run these commands as root because Heroku will not allow you too). After trying everything, it seems like I should follow these instructions from Heroku, which gets printed to my terminal after running python setup.py install:
".....If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable."
I am not sure how to go about this. Any help wold be much appreciated.
Also, I have come across a few stack overflow posts but none have been able to help so far. Let me know if you need any more info from me.
TL;DR - Installing a python module/library on Heroku.
add a requirements.txt file to your python deployment.
Write your python dependencies in it (add any other dependencies you have not only pycurl).
check this doc from heroku guys
I use pycurl on my heroku app and have found no problem uploading to heroku..
Installing dependencies using Pip (1.3.1)
Downloading/unpacking pycurl==7.19.0 (from -r requirements.txt (line 11))
Running setup.py egg_info for package pycurl
Using curl-config (libcurl 7.19.7)
Installing collected packages: pycurl
Running setup.py install for pycurl
Using curl-config (libcurl 7.19.7)
building 'pycurl' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_CURL_OPENSSL=1 -DHAVE_CURL_OPENSSL=1 -DHAVE_CURL_SSL=1 -I/app/.heroku/python/include/python2.7 -c src/pycurl.c -o build/temp.linux-x86_64-2.7/src/pycurl.o
src/pycurl.c: In function ‘do_multi_info_read’:
src/pycurl.c:2843: warning: call to ‘_curl_easy_getinfo_err_string’ declared with attribute warning: curl_easy_getinfo expects a pointer to char * for this info
src/pycurl.c: In function ‘multi_socket_callback’:
src/pycurl.c:2355: warning: call to ‘_curl_easy_getinfo_err_string’ declared with attribute warning: curl_easy_getinfo expects a pointer to char * for this info
In function ‘util_curl_unsetopt’,
inlined from ‘do_curl_unsetopt’ at src/pycurl.c:1551:
src/pycurl.c:1476: warning: call to ‘_curl_easy_setopt_err_CURLSH’ declared with attribute warning: curl_easy_setopt expects a CURLSH* argument for this option
gcc -pthread -shared build/temp.linux-x86_64-2.7/src/pycurl.o -lcurl -lidn -lssl -lcrypto -llber -lldap -lrt -lgssapi_krb5 -lgssapi_krb5 -lssl -lcrypto -lz -o build/lib.linux-x86_64-2.7/pycurl.so /usr/lib/libcurl.a
Successfully installed pycurl

How can I install MySQL-python via pip/virtualenv for Python 2.5 on a Linux system with Python 2.6?

I am trying to set up a virtualenv for a Django project. It needs MySQL-python. I'm trying to replicate the production environment, which uses Python 2.5. My Ubuntu desktop has Python 2.5. I can install the Python 2.5 virtualenv with virtualenv --python=/usr/bin/python2.5 .... However when I try to pip install MySQL-python, I get this output:
$ pip install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.5 -c _mysql.c -o build/temp.linux-i686-2.5/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:29:
pymemcompat.h:10: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
I have installed the python-dev Ubuntu deb package, but that's for Python 2.6.
How else can I get MySQL-python installed?
I had this same problem on an Ubuntu box. Prior to installing MySQL-python via pip, I needed to compile the module and dependencies from source using the following command:
sudo apt-get build-dep python-mysqldb
see this article - http://theviceprogrammer.com/?p=238
Actually, found a solution, I enabled the Dead Snakes - old python version repository, then I could aptitude install python2.5-dev, and then pip install MySQL-python worked
Instead of using pip or easy_install, you can use apt-get:
sudo apt-get install python-mysqldb
Requiring from source as per adam's reply wasn't require for me, on Ubuntu 12.04 w/ Python 2.5

How to install SSL for python 2.5 on Debian Linux?

Question
How do I install SSL for Python 2.5 on Debian?
I have tried:
sudo easy_install ssl
But getting:
$ python setup.py build
looking for /usr/include/openssl/ssl.h
looking for /usr/include/krb5.h
running build
running build_py
running build_ext
building 'ssl._ssl2' extension
creating build/temp.linux-i686-2.5
creating build/temp.linux-i686-2.5/ssl
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./ssl/2.5.1 -I/usr/include/python2.5 -c ssl/_ssl2.c -o build/temp.linux-i686-2.5/ssl/_ssl2.o
In file included from ssl/_ssl2.c:75:
./ssl/2.5.1/socketmodule.h:45:33: error: bluetooth/bluetooth.h: No such file or directory
./ssl/2.5.1/socketmodule.h:46:30: error: bluetooth/rfcomm.h: No such file or directory
./ssl/2.5.1/socketmodule.h:47:29: error: bluetooth/l2cap.h: No such file or directory
./ssl/2.5.1/socketmodule.h:48:27: error: bluetooth/sco.h: No such file or directory
In file included from ssl/_ssl2.c:75:
./ssl/2.5.1/socketmodule.h:98: error: field ‘bt_l2’ has incomplete type
./ssl/2.5.1/socketmodule.h:99: error: field ‘bt_rc’ has incomplete type
./ssl/2.5.1/socketmodule.h:100: error: field ‘bt_sco’ has incomplete type
error: command 'gcc' failed with exit status 1
Solution
sudo apt-get install libbluetooth-dev
sudo rm /usr/lib/python2.5/site-packages/ssl/__init__.pyc
For reference, you must install libbluetooth-dev.
In fact, you shouldn't compile your own version of python ssl module for several reasons:
you won't get automatic security updates of your python ssl module;
you won't get smooth upgrade path if you decide to upgrade Debian system on your server.
The best way to obtain python ssl module is to install it from official Debian repositories using apt-get:
apt-get install python-openssl
Hope this helps.

Categories