Martin Thoma
Martin Thoma

Reputation: 136257

Why do I get 'ImportError: dynamic module does not define init function (PyInit__caffe)' in ipython notebook while it works for Python?

I try to get the examples/classification.ipynb from the BVLC/caffe to work. When I Python 2.7.8 via console, it works. I can import caffe and (after a few seconds) its just finished. No error message. No need to append something to the sys.path.

When I start the example mentioned above and execute the first Python cell, I get an error. To make it simpler, I added a cell with only import caffe which gives me:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-1cca3aa1f8c5> in <module>()
----> 1 import caffe

/home/moose/GitHub/caffe/python/caffe/__init__.py in <module>()
----> 1 from .pycaffe import Net, SGDSolver
      2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver
      3 from .proto.caffe_pb2 import TRAIN, TEST
      4 from .classifier import Classifier
      5 from .detector import Detector

/home/moose/GitHub/caffe/python/caffe/pycaffe.py in <module>()
     11 import numpy as np
     12 
---> 13 from ._caffe import Net, SGDSolver
     14 import caffe.io
     15 

ImportError: dynamic module does not define init function (PyInit__caffe)

What is the problem here?

Do I eventually have the wrong version?

$ ipython notebook --version
3.0.0

Upvotes: 2

Views: 4670

Answers (1)

LiberiFatali
LiberiFatali

Reputation: 315

When you work with caffe in the ipython session. You should add caffe root folder to sys.path. From my experience, Ipython doesn't load PYTHONPATH variable like using Python in console.

Upvotes: 1

Related Questions