76

Hello when I attempt to install pylibmc on OSX Lion using pip I get the following error:

./_pylibmcmodule.h:42:10: fatal error: 'libmemcached/memcached.h' file not found

#include <libmemcached/memcached.h>

         ^

1 error generated.

error: command 'clang' failed with exit status 1

Any clues at how to solve this issue?

harristrader
  • 1,181
  • 2
  • 13
  • 20
  • Do you have the libmemcached headers installed anywhere? – Martijn Pieters Feb 10 '13 at 22:26
  • Thanks, I faced this error while installing requirements for running djangoproject's tests. Posting it here so that if somehow new contributors face this issue and reach here, they can confidently rely on the solution `brew install libmemcached` – Deep Mar 27 '20 at 13:28

10 Answers10

143

libmemcached may also be installed using Homebrew.

brew install libmemcached

After that, pip install pylibmc worked for me without needing to specify any additional arguments.

Jeremy
  • 1
  • 85
  • 340
  • 366
  • 30
    I installed it using homebrew and it was correctly linked, although pylibmc couldn't find it either way. So I had to point the libmemcached directory when installing pylibmc by running `sudo pip install pylibmc --install-option="--with-libmemcached=/usr/local/Cellar/libmemcached/1.0.18/"` – marcelosalloum Aug 28 '14 at 18:25
  • 1
    You can try `brew unlink libmemcached`, then `brew link libmemcached`. In my case the links were messed up. This should create links such that `/usr/local/include/libmemcached/memcached.h` exists. – Neil Apr 06 '15 at 22:00
  • 5
    These solutions didn't work for me. I had to ```export CPPFLAGS="-I/usr/local/include"``` and ```export LDFLAGS="-L/usr/local/lib"``` – giles Jun 08 '16 at 20:33
  • `brew unlink libmemcached` then `brew link memcached` worked for me! Thanks @Neil – steve Mar 23 '17 at 21:39
  • The defaults have changed at some point and you need to make sure CFLAGS/LDFLAGS are set. The best way to do this is to use `pkg-config` (`brew install pkg-config` if you don't have it) so the current installed version is used for the include & library files: `CFLAGS=$(pkg-config --cflags libmemcached) LDFLAGS=$(pkg-config --libs libmemcached) pip install pylibmc` – Chris Adams Jan 02 '19 at 14:41
  • I am installing pylibmc on windows but it is failing due to libmemcached and while installing libmemcached it is giving error of cmemcached_imp.c cannot be executed? Any help for windows platform @ChrisAdams – abhishek Feb 20 '19 at 13:48
  • 2
    With modern installations of Homebrew, you may need to point to the new Homebrew root which is no longer in /usr/local: `LIBMEMCACHED=/opt/homebrew pip install pylibmc` – btown Dec 19 '21 at 04:51
  • 1
    `CPPFLAGS="-I/opt/homebrew/include" pipenv install` worked for me for M1, have not tried the shorter path though. – Andrei Apr 30 '22 at 07:51
38

It's in the libmemcached package. To install it using macports:

sudo port install libmemcached

Then, assuming you're using pip:

pip install pylibmc --install-option="--with-libmemcached=/opt/local"

or

LIBMEMCACHED=/opt/local pip install pylibmc

as explained in the pylibmc docs.

Mike Fogel
  • 3,127
  • 28
  • 22
33

I solved this issue by checking where memcached is installed

$ which memcached
/usr/local/bin/memcached

and then setting LIBMEMCACHED environment variable before pip install:

$ export LIBMEMCACHED=/usr/local
$ pip install pylibmc
Aidas Bendoraitis
  • 3,965
  • 1
  • 30
  • 45
18

Answer for Ubuntu users:

sudo apt install libmemcached-dev zlib1g-dev
fluffy
  • 5,212
  • 2
  • 37
  • 67
7

I have the same problem because i have installed MEMCACHED and not LIBMEMCACHED, so, to resolve:

brew uninstall memcached #to remove wrong package

brew install libmemcached #install correct lib

pip install pylibmc

Its Works for me!

: )

Giuseppe Lopes
  • 101
  • 1
  • 7
  • Brew declined to uninstall memcached because libmemcached is an installed dependency; so I expect what you've actually done is reinstall `memcached`. – John Mee May 22 '19 at 03:59
6

For those finding this answer on Fedora:

sudo yum install libmemcached-devel

Jamie
  • 2,181
  • 1
  • 21
  • 35
3

Hit the same error with macOS High Sierra, Python3.6 installed with brew. Solution for me was to export these flags, mentioned in this comment: Error when install pylibmc using pip

export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include"

After that, pip install run just fine.

2

i fixed this by installing memcached from port

you should install first macports from http://www.macports.org/

then run this command

sudo port install memcached

after that download the pylibmc from the pypi http://pypi.python.org/pypi/pylibmc extract .tar.gz file then

python setup.py install --with-libmemcached=/opt/local
mohd
  • 2,634
  • 2
  • 16
  • 18
2

this code is worked for me

  sudo apt-get install libmemcached-dev zlib1g-dev

  LIBMEMCACHED=/opt/local pip install pylibmc
Sarath Ak
  • 7,903
  • 2
  • 47
  • 48
0

Sometimes the X-Code Command Line Tools need to be installed.

 xcode-select -p
Twitch
  • 664
  • 1
  • 7
  • 26