1

Trying caffe python examples from: http://caffe.berkeleyvision.org/tutorial/interfaces.html gives me error:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
caffe_root = '/opt/caffe'
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-18cb333d5c1b> in <module>()
      7 sys.path.insert(0, caffe_root + 'python')
      8 
----> 9 import caffe

...
...

/usr/lib/python2.7/site-packages/scipy/signal/__init__.py in <module>()
    272 from __future__ import division, print_function, absolute_import
    273 
--> 274 from . import sigtools
    275 from .waveforms import *
    276 from ._max_len_seq import max_len_seq

ImportError: cannot import name sigtools

Apparently the sigtools import fails, but I can't figure out why. The /usr/lib/python2.7/site-packages/scipy/signal contains all files:

$ ls -1 /usr/lib/python2.7/site-packages/scipy/signal/sign*
/usr/lib/python2.7/site-packages/scipy/signal/signaltools.py
/usr/lib/python2.7/site-packages/scipy/signal/signaltools.pyc

In general, how python process directives like this, specifically what dot is resolved to if my working directory was completely different from the location where sigtools package is located?

from . import sigtools
Dimon Buzz
  • 1,130
  • 3
  • 16
  • 35

1 Answers1

0

As stated here:

`from ... import` vs `import .`

"from . import sigtools" imports the main module "." (which is "signal") than imports the object/module sigtools. If "." has been already imported it rely on that structure.

I think that this can be tricky in case you have 2 modules with the same name in the python import path: the interpreter imports the first one found and never imports the second one. If the second one has more modules than the first one, this can lead to something similar to your problem.

J_Zar
  • 2,034
  • 2
  • 21
  • 34
  • According to the traceback "from . import" happens only one time for sigtools only, so this is not seems to be the case. – Dimon Buzz Mar 04 '16 at 13:58