3

I am unable to import python modules in the terminal when I open python from a normal user(although, its working for root user) :
The error I get is this :

import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 58, in <module>
    from numpy.testing.nosetester import _numpy_tester
  File "/usr/lib/python2.7/dist-packages/numpy/testing/__init__.py", line 12, in <module>
    from . import decorators as dec
  File "/usr/lib/python2.7/dist-packages/numpy/testing/decorators.py", line 21, in <module>
    from .utils import SkipTest
  File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 15, in <module>
    from tempfile import mkdtemp, mkstemp
  File "/usr/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/home/praneeth/computervision/code/caffe-master/distribute/python/caffe/io.py", line 2, in <module>
    import skimage.io
  File "/home/praneeth/scikit-image/skimage/__init__.py", line 158, in <module>
    from .util.dtype import *
  File "/home/praneeth/scikit-image/skimage/util/__init__.py", line 1, in <module>
    from .dtype import (img_as_float, img_as_int, img_as_uint, img_as_ubyte,
  File "/home/praneeth/scikit-image/skimage/util/dtype.py", line 8, in <module>
    dtype_range = {np.bool_: (False, True),
AttributeError: 'module' object has no attribute 'bool_'

Its the same with all modules not just numpy. I have tried the solutions suggested in the other similar questions, but they haven't worked out. For eg : Cannot import a python module that is definitely installed (mechanize)

The output of the command $PYTHONPATH is :

/home/praneeth/computervision/code/caffe-master/distribute/python/caffe:/home/praneeth/computervision/code/caffe-master/python/caffe:/usr/lib/python2.7/dist-packages/

Also, my system path without root permission is :

import sys
sys.path
    ['', '/home/praneeth/computervision/code/caffe-master/distribute/python/caffe', '/home/praneeth/computervision/code/caffe-master/python/caffe', '/usr/lib/python2.7/dist-packages', '/home/praneeth', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/home/praneeth/scikit-image', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0']

Edit1: sys.path with root user is found to be same as that of without root user expect those caffe installation paths. Here is the result with root user:

sudo python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/home/praneeth/scikit-image', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
Community
  • 1
  • 1
praneeth
  • 369
  • 4
  • 20
  • I would try reinstalling Python if I were you – Andrew Che Mar 13 '17 at 08:40
  • Can you add also `sys.path` for root user and discover differences? Also, please specify how you installed python and numpy. – wanderlust Mar 13 '17 at 09:24
  • have a look into my **edit1** for sys.path with root user. Also, I have installed numpy using both `sudo apt-get install python-numpy` and `sudo pip install numpy` separately and gave it a try. Both of them didn't work – praneeth Mar 13 '17 at 10:15
  • Strange!! even reinstalling of python didn't work actually. Seems like the problem is with Caffe installation. I should look into it once. – praneeth Mar 13 '17 at 10:17

1 Answers1

0

Finally got it resolved!! The problem is because of installing numpy and scipy (with a different version) separately for python and numpy of some other version while installing caffe. There is a version conflict between two numpy and scipy related libraries and as a result, python interpretor was unable to import them.

Reinstalled caffe properly once again without any version conflict this time and the problem got resolved.

Thanks for the help

praneeth
  • 369
  • 4
  • 20