8
$\begingroup$

I'm compiling an external C package for my Blender 2.78a Python 3.5.

My compiling script looks like

from distutils.core import setup, Extension
import numpy
setup(name='_tifffile', ext_modules=[Extension('_tifffile', ['tifffile.c'], include_dirs=[n
umpy.get_include()])])

Upon running it, I got

tifffile.c:71:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

I looked into /blender-2.78a-linux-glibc211-x86_64/2.78/python/include/python3.5m/ and indeed didn't see Python.h.

In general Python community, people suggest simply uninstalling the current Python and reinstalling the dev version. I don't wanna hack the Python bundled with Blender like that.

How can I solve this problem?

$\endgroup$
1
  • $\begingroup$ I realize this is actually a frequently occurring problem. In the past 10 days, while I was using Blender Python's pip to install modules, I had this problem twice. $\endgroup$ Jul 25, 2017 at 20:11

2 Answers 2

9
$\begingroup$

First, if you install blender with your linux distro, then a proper installation of python3 and blender with your particular distro should solve your problem.

e.g. for debian:

  1. sudo apt-get install python3 python3-dev
  2. sudo apt-get install blender

Second, if you really want to install the python header files for the python that runs inside blender, then you can do it the following way:

Find out the exact blender python version:

  1. /path/to/blender-2.78a-linux-glibc211-x86_64/2.78/python/bin/python3.5m -V

Download and install the python header files from the official python homepage:

  1. point your browser at https://www.python.org/downloads/source/
  2. download Gzipped source tarball from the exact same python version as your blender python version
  3. cd ~/Downloads/
  4. tar -xzf Python-3.X.X.tgz
  5. cp Python-3.X.X/Include/* /path/to/blender-2.78a-linux-glibc211-x86_64/2.78/python/include/python3.5m/

That should get you rolling. Best, Bue

$\endgroup$
8
  • $\begingroup$ I went with Option #2, and it was awesome. Thanks! $\endgroup$ Aug 17, 2020 at 21:01
  • $\begingroup$ @SibbsGambling :' ). Tnx! $\endgroup$
    – bue
    Oct 19, 2020 at 3:30
  • $\begingroup$ I'm also trying option #2, but I'm getting an error from cp saying that the location is read only (so it can't copy in). I've installed Blender using snap. Please let me know how this can be resolved! $\endgroup$
    – Microbob
    Dec 1, 2020 at 0:59
  • $\begingroup$ hi @Microbob ! Try: chmod +w -R /path/to/blender-2.78a-linux-glibc211-x86_64/2.78/python/include/python3.5m/ but be VERY CAREFUL with this command that you only execute it on this particular folder. It is easy to mess up your whole operating system installation if you for example execute this command on your root folder. Actually, before you do this you should read about the unix command chmod and chow that you at least a little bit know what's going on! here are the links: en.wikipedia.org/wiki/Chmod en.wikipedia.org/wiki/Chown $\endgroup$
    – bue
    Dec 2, 2020 at 1:33
  • $\begingroup$ Actually, you said, you installed blender installed with snap. I have not experiences snap, but as far as I understand, snap is similar to flatpak makes a container around each installation. Could you find your /path/to/blender-2.78a-linux-glibc211-x86_64 ? I think this whole thing will not work with a snap installation because you have to find a way into the container, and I doubt that you did. $\endgroup$
    – bue
    Dec 2, 2020 at 1:57
0
$\begingroup$

You have to install the Python development package. In Ubuntu is python3-dev (if you are using Python3). So:

sudo apt install python3-dev

$\endgroup$
4
  • $\begingroup$ I'm talking about the python bundled with Blender. $\endgroup$ Aug 1, 2017 at 19:33
  • $\begingroup$ Have you tried to install the version of Python you need with dev tools in a custom directory and make the Blender path to point to it then? I don't see how the Python version bundled with Blender can be different from the standard library, assuming they are the same version $\endgroup$ Aug 2, 2017 at 9:15
  • $\begingroup$ How does one " make the Blender path to point to it"? It would be great if this actually is possible. Thanks $\endgroup$ Aug 3, 2017 at 21:42
  • $\begingroup$ Try set environment variables properly: blender.org/forum/viewtopic.php?t=25657 $\endgroup$ Aug 4, 2017 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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