I am trying to import tensorflow into blender, but I get an error when I do. It says

 RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
  File "/Users/me/project/bin/Script.blend/Text", line 6, in <module>
  File "/Users/me/project/bin/TensorFlow.py", line 7, in <module>
import tensorflow
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 50, in <module>
from tensorflow.python.framework.framework_lib import *
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/python/framework/framework_lib.py", line 62, in <module>
from tensorflow.python.framework.ops import Graph
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 40, in <module>
from tensorflow.python.framework import versions
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/python/framework/versions.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
  File "/Users/me/project/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/Applications/Blender/blender.app/Contents/Resources/2.73/python/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
SystemError: initialization of _pywrap_tensorflow raised unreported exception

How can I import it without the error? It works well outside of Blender.
I'm using Blender 2.73 and it uses my local python 3.4.2.

  • 1
    $\begingroup$ Can you give us a step-by-step of how you got this error? Also, is this the entire error you received? I tried importing it a specific way, and while the last line is the same as yours, there's a bunch of stuff preceding it too. $\endgroup$ – Mike Belanger Jan 8 '16 at 16:08
  • $\begingroup$ I got the error from putting the line "import tensorflow". I did have a bunch of stuff before it but I wasn't sure if that was part of the error. $\endgroup$ – user2888499 Jan 8 '16 at 21:11
  • $\begingroup$ If we see the entire error message we might be able to help you more. For instance, the error I had started with something about the version of numpy its using. $\endgroup$ – Mike Belanger Jan 8 '16 at 23:53

The problem: Blender has bundled numpy with a version not compatible with your tensorflow version.

Solution: Use a blender version with a compatible bundled numpy.

I imported it on my machine successfully with Blender 2.72b with my system python 3.4.3

I use Gentoo Linux but it should not be problem. Please try Blender 2.72b

| improve this answer | |

if you want to solve any compatibility problems you can execute your tensorflow code outside of blender environment.

On blender you can execute your code using os library. You can read output with the standard output, formatting it with json.

import subprocess
from subprocess import STDOUT

app_path = "python3 yourdir/yourapp.py"
youroutput = subprocess.check_output(app_path, stderr=STDOUT, shell=True)
| improve this answer | |
  • 2
    $\begingroup$ How can I execute the code outside of the environment? $\endgroup$ – user2888499 Jan 8 '16 at 21:13
  • 1
    $\begingroup$ It depends on the OS that you have. Using the module subprocess you can do this: youroutput=subprocess.check_output("python3 yourdir/yourapp.py", stderr=subprocess.STDOUT, shell=True) $\endgroup$ – user36531 Jan 13 '16 at 10:16

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.