64

I am using amazon ec2 ubuntu 11.04 server

 sudo pip install python-snappy 

also I tried to downloaded package and entered "sudo python setup.py install"

I got the error:

  running build
  running build_ext
  building 'snappy' extension
  gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c snappymodule.cc -o build/temp.linux-x86_64-2.7/snappymodule.o
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
  snappymodule.cc:31:22: fatal error: snappy-c.h: No such file or directory
  compilation terminated.
  error: command 'gcc' failed with exit status 1

How i could get rid of this error?

source: https://github.com/andrix/python-snappy

4
  • 3
    install snappy C library.
    – jfs
    Jul 10, 2012 at 14:57
  • 4
    Can you share how do you install snappy C library? Add that to the path before python install or sth else. Thanks
    – B.Mr.W.
    Aug 26, 2013 at 21:50
  • URL changed for snappy C: google.github.io/snappy Jan 9, 2020 at 14:54
  • What about on windows?
    – wawawa
    Dec 2, 2020 at 11:00

16 Answers 16

144

You can install Snappy C library with following commands:

DEB-based: sudo apt-get install libsnappy-dev

RPM-based: sudo yum install csnappy-devel

Alpine (Docker) apk add --no-cache snappy-dev g++

openSUSE: sudo zypper in snappy-devel

MacOS: See Riley's answer below.

5
  • 5
    if on a mac and brew is installed, then brew install snappy also works.
    – bsegraves
    Jan 7, 2015 at 3:09
  • 21
    I think it is sudo yum install snappy-devel May 15, 2016 at 3:40
  • 1
    Its (tried on centos7) yum install csnappy-devel Feb 16, 2017 at 14:39
  • Thanks sudo apt-get install libsnappy-dev worked for me, I am using ubuntu 18.04 and python 3.6.9 Aug 24, 2020 at 5:24
  • 1
    For alpine linux (for docker) apk add --no-cache snappy-dev g++ solved the problem Feb 9, 2023 at 11:10
60

According to the repo

How to install it on Mac OS X?

It has been reported a few times (Issue #7 and #23) that it can't be installed correctly the library in Mac. The procedure should be,

$ brew install snappy # snappy library from Google 
$ CPPFLAGS="-I/usr/local/include -L/usr/local/lib" pip install python-snappy
4
  • 4
    The CPPFLAGS part was essential. This is missing from every other answer, and very hidden in the python-snappy docs.
    – mcskinner
    Apr 17, 2020 at 6:14
  • 20
    CPPFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" for Apple Silicon
    – villasv
    Feb 3, 2022 at 20:32
  • Just an FYI - appending the CPPFLAGS to poetry install didn't work but going into shell and doing pip install with the prepended Env works.
    – David
    Mar 9, 2023 at 22:59
  • @David for poetry install, i had to export, not just appending
    – ealeon
    Nov 2, 2023 at 17:20
22

You need Snappy C library

Then you have to install python-snappy wrapper.

It seems you didn't install Snappy-C library

Try it ..as already a fellow commented for your post

UPDATE: See more highly upvoted post below, which includes instructions to install on DEB-based, RPM-based, and Mac OS (Brew).

4
  • on RPM-based execute: wget url_to_download_snappy; tar xf snappy-x.y.z.tar.gz; cd snappy-x.y.z; ./configure; make install; pip install python-snappy
    – Zahra
    Jun 12, 2017 at 21:57
  • Snappy library has moved to github, thus it won't work anymore Feb 6, 2019 at 10:47
  • 1
    For Debian based system, following should work : sudo apt-get install libsnappy-dev Jul 8, 2020 at 7:23
  • sudo apt-get install libsnappy-dev -> worked got ubuntu! Dec 8, 2020 at 19:30
3

I had some trouble getting snappy to install. Finally downloaded the pre-build stuff as offered by https://www.lfd.uci.edu/~gohlke/pythonlibs/ and all went well. (Unofficial Windows Binaries for Python Extension Packages)

3

for Oracle Linux with Python 3.X:

you need to enable optional_latest repository as a first step,

  1. use for enabling the following repo

    $ yum-config-manager --enable ol7_optional_latest

    "ol7_optional_latest" repo will be enabled for yum lookup.

  2. then install packages using,

    $ yum -y install gcc gcc-c++ snappy snappy-devel

  3. then with pip install the python-snappy package,

    $ pip3 install python-snappy

1
2
  1. You download snappy lib at here: https://code.google.com/p/snappy/
  2. Extract it
  3. Install by command lines follows: $: ./configure $: make $: make install
  4. Install python-snappy: $: pip install python-snappy
2

had lots of issues installing on El Capitan, with an error saying that the snappy-c.h file was not found.

Had to install snappy from tar.gz file https://github.com/google/snappy/releases/download/1.1.3/snappy-1.1.3.tar.gz

untar and run

./configure
make
make install

it will put the header file in /usr/local/include

then needed to set FLAGS for the cc compiler to find the header file:

export DYLD_LIBRARY_PATH=/usr/local/include
export CPPFLAGS="-I/usr/local/include/snappy-c.h"
export CFLAGS="-I/usr/local/include/snappy-c.h"
export CXXFLAGS="-I/usr/local/include/snappy-c.h"
export LDFLAGS="-L/usr/local/lib"

and then I installed python-snappy from the egg file https://pypi.python.org/packages/b1/fe/1d632cdac5dbb5ce84db778af7f733eb469130d8cf4c02f6cd9057a96768/snappy-2.4.1-py2.7-macosx-10.5-intel.egg#md5=b76558c71f1d97feeb8402c345e466bf

you can try with pip install python-snappy but it originally failed to find the header file, so i went for the egg file

to install the egg:

easy_install <eggfile>
python setup.py build
python setup.py install
2

You need to check the output for

rpm -q snappy-devel

If it is not present, then install it using this command:

yum install snappy-devel
2

If you are on Mac OS X Catalina, you can install with

brew install snappy
CPPFLAGS="-I/usr/local/include -L/usr/local/lib -stdlib=libc++ " pip install python-snappy

as suggested by https://github.com/andrix/python-snappy FAQ

2

Fix for macOS M1. You have to define absolute path to lib and include for snappy.

brew install snappy
pip install \                               
  --upgrade --ignore-installed \
  python-snappy==0.5.4 \
  --global-option=build_ext \
  --global-option="-I/opt/homebrew/Cellar/snappy/1.1.9/include" \
  --global-option="-L/opt/homebrew/Cellar/snappy/1.1.9/lib"
1
  • This didn't work for me.
    – AInguva
    Dec 12, 2023 at 15:30
0

This fixed my issue:

yum install gcc-c++  
0

I was having troubles with this for a while. FYI I'm trying to install Crossbar (https://crossbar.io/docs/Installation-on-Linux/)

I did a bunch of googling and messed around quite a bit. I'm using Python 3.7.4 and what I think solved my problem is this :

sudo yum install python-devel

if that doesn't work try

sudo yum install python3-devel

source:

https://github.com/giampaolo/psutil/issues/1143#issuecomment-475354786

https://github.com/giampaolo/psutil/issues/1143

0

To solve this issue in Mac OS X with MacPorts installed, you can do:

$ sudo port install snappy
$ CPPFLAGS="-I/opt/local/include -L/opt/local/lib" pip install python-snappy
0

For Windows

  1. Download from here
  1. Extract the Zip.

  2. Copy the .h files from include folder. Paste in to the python installation folder C:\Users\user\AppData\Local\Programs\Python\Python310\include\

  3. Copy snappy64.lib from native folder. Paste in to python installation folder C:\Users\user\AppData\Local\Programs\Python\Python310\libs\

  4. Rename snappy64.lib to snappy.lib

  5. you are good to go. Re-try command pip install -r .\requirements.txt

0
conda install snappy

is ok for me

0

Mac OS - Apple Silicon

If you have Apple Silicon, home-brew installs to /opt/homebrew by default.

So, the command changes to:

$ brew install snappy
$ CPPFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" pip install python-snappy

For Intel Silicon, you need the path to be /usr/local/include & /usr/local/lib as suggested above.

FYI: By -I & -L, we ask pip to look for include and library files in the homebrew directory resp. (where snappy and other brew packages would be located).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.