# Error when installing requirements for django tests - fatal error: 'libmemcached/memcached.h' file not found #include \<libmemcached/memcached.h\>

**URL:** <https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685>\
**Category:** Django Internals\
**Created:** [March 27, 2020, 1:33pm UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685 "2020-03-27T13:33:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProProgrammer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/proprogrammer/32/490_2.png) [@ProProgrammer](https://forum.djangoproject.com/u/ProProgrammer)\
**Post date:** [March 27, 2020, 1:33pm UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/1 "2020-03-27T13:33:34Z")

</div>

Environment: macOS Catalina 10.15.4  
Python Version: 3.8.2 installed through `pyenv`

TL;DR solution:

- You need to install `libmemcached` - `brew install libmemcached` if you are using homebrew. If not, first install homebrew using instructions on [https://brew.sh](https://brew.sh) and then execute `brew install libmemcached`

_Exact error observed and Solution used is as posted on [this StackOverflow question.](https://stackoverflow.com/a/19432949/2661238) Posting this here for ease of finding for new contributors (like myself 😃)_

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [March 27, 2020, 2:22pm UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/2 "2020-03-27T14:22:15Z")

</div>

The contributing docs on running the tests ( [Unit tests | Django documentation | Django](https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#running-all-the-tests) ) say:

> If you encounter an error during the installation, your system might be missing a dependency for one or more of the Python packages. Consult the failing package’s documentation or search the Web with the error message that you encounter.

I wonder if we should document these? I guess the problem is there are 17 main dependencies at the moment and that crossed with the various operating systems makes a lot of potential commands to run.

---

<div class="post-metadata">

**Author:** ![ProProgrammer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/proprogrammer/32/490_2.png) [@ProProgrammer](https://forum.djangoproject.com/u/ProProgrammer)\
**Post date:** [March 27, 2020, 3:17pm UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/3 "2020-03-27T15:17:07Z")

</div>

Hey @adamchainz, thanks for sharing context and link to documentation.

I agree, calling out every single command to run to install all the dependencies is probably not a maintainable approach, however I like the idea of just documenting these dependencies in the [running-all-the-tests](https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#running-all-the-tests) section so new contributors do not find it overwhelming when they see an unknown/unrelated issue pop up and do not feel discouraged in the newly started journey of contributing to Django.

This also aligns with the thought, calling out commands to run might require a lot of regular updates to the documentation since the commands might change or internal dependencies for packages might change as the dependencies themselves evolve however the fact that they are a dependency for Django tests to run, is under Django’s control hence just calling out the names of dependencies won’t be a too big off a task to achieve and maintain.

Would love to hear more thoughts on this.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 2, 2020, 10:13pm UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/4 "2020-04-02T22:13:34Z")

</div>

If you can make a documentation patch that’s not too big, I’d like to see it. I know at least the memcached headers thing has been the same for years since memcached is very stable.

---

<div class="post-metadata">

**Author:** ![Valz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/valz/32/701_2.png) [@Valz](https://forum.djangoproject.com/u/Valz)\
**Post date:** [April 2, 2020, 10:31pm UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/5 "2020-04-02T22:31:50Z")

</div>

I had a similar problem when I was following the PostGIS documentation for Windows. It’d definitely be nice to have a clear idea of what the dependencies for each system are, not the exact commands or the steps to take.

I’ll start working on a documentation patch. Let me know what the exact dependencies for macOS are and I’ll add them.

---

<div class="post-metadata">

**Author:** ![nanliu](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@nanliu](https://forum.djangoproject.com/u/nanliu)\
**Post date:** [April 3, 2020, 6:13am UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/6 "2020-04-03T06:13:41Z")

</div>

```auto
export LIBMEMCACHED=/usr/local

```

This one works for me! I am also new to Django open source!

---

<div class="post-metadata">

**Author:** ![ProProgrammer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/proprogrammer/32/490_2.png) [@ProProgrammer](https://forum.djangoproject.com/u/ProProgrammer)\
**Post date:** [April 4, 2020, 4:09am UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/7 "2020-04-04T04:09:40Z")

</div>

Thanks @adamchainz I searched for `libmemcached` on Django Trac to ensure no one else is already working or has worked in the past and found [this comment by Tim Graham](https://code.djangoproject.com/ticket/27876):

> I’m not a mac OS user so I can’t say for sure what the issue is here. What does “it always show problems in installing pylibmc and libmemcached” mean? My guess is that the equivalent of `libmemcached-dev` (Debian package) isn’t installed. ([​related StackOverflow](https://stackoverflow.com/questions/9070218/error-when-trying-to-install-pylibmc-on-mac-osx-lion)). I think it’s not Django’s job to document the requirements of third-party packages. I’d rather enhance [​pylibmc’s install instructions](http://sendapatch.se/projects/pylibmc/install.html) if needed.

This was then again [raised in May 2018](https://code.djangoproject.com/ticket/29405) where Tim again mentioned that we won’t be documenting this as a dependency.

> The issue has been raised before and the consensus is that it’s not Django’s job to document all the possibilities for various operating systems.

Now 2 years after that, I (and seems some others too) observed it again and we discussed through this forum.

I think given the recurrence of this issue (several times over half a decade), we should rethink our stance and call out them at least in the [Troubleshooting section](https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#troubleshooting) of the contributing guide. This only reduces the hurdle for new contributors.

In the spirit of this, I have created a patch here [Doc'd troubleshooting steps for failures when test requirements by ProProgrammer · Pull Request #12660 · django/django · GitHub](https://github.com/django/django/pull/12660)

---

<div class="post-metadata">

**Author:** ![shangxiao](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shangxiao/32/10313_2.png) [@shangxiao](https://forum.djangoproject.com/u/shangxiao)\
**Post date:** [October 27, 2023, 8:53am UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/8 "2023-10-27T08:53:34Z")

</div>

FYI with homebrew now located in /opt/homebrew I had to let pip know where to find it:

```auto
LIBMEMCACHED=/opt/homebrew pip install pylibmc

```

---

<div class="post-metadata">

**Author:** ![lancemarks](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lancemarks/32/31239_2.png) [@lancemarks](https://forum.djangoproject.com/u/lancemarks)\
**Post date:** [January 16, 2026, 4:15am UTC](https://forum.djangoproject.com/t/error-when-installing-requirements-for-django-tests-fatal-error-libmemcached-memcached-h-file-not-found-include-libmemcached-memcached-h/1685/9 "2026-01-16T04:15:50Z")

</div>

LIBMEMCACHED=/opt/homebrew/Cellar/libmemcached/1.0.18\_2 python3 -m pip install -r requirements/py3.txt
