0

I have a python module at /home/amit/folder1/folder2/folder3/folder4/folder5/nbsearch named neighbourhoodsearch.py. I have included a class in this file in another module at /home/amit/folder1/folder2/folder3/folder4/controller named nbsearch_controller.py.

from neighbourhoodsearch import NeighbourhoodSearch

I have added the path /home/amit/folder1/folder2/folder3/folder4/folder5/nbsearch to PYTHONPATH using sys.path.append and added a file __init__.py in all the folders in the path. But still when I run the file nbsearch_controller.py, it says

ImportError: No module named neighbourhoodsearch
Avión
  • 7,963
  • 11
  • 64
  • 105
amitmac
  • 1
  • 1
  • 4
  • Having `__init__.py` files in `nbsearch` and `controller` folders and adding `nbsearch` to the path with `sys.path.append("/home/amit/folder1/folder2/folder3/folder4/folder5/nbsearch")` should be enough. – filaton Mar 30 '16 at 12:18
  • Why won't it work? I have checked the file/folder names also. Everything seems fine. – amitmac Mar 30 '16 at 13:10

2 Answers2

0

You can try multiple things:

  • triple-check for typos in the path you give
  • print sys.path before your problematic import and make sure that your path is really there
  • remove .pyc files in your directory structure if you have some
  • check the result of os.path.isfile("/home/amit/folder1/folder2/folder3/folder4/folder5/nbsearch/neighbourhoodsearch.py") (it should return True)

  • check that you have "read" rights on your Python files

filaton
  • 2,257
  • 17
  • 27
-1

See this question: Import a module from a relative path

You have the init.py file, so you should be good.

Community
  • 1
  • 1
RandomCoder
  • 2,071
  • 4
  • 12
  • 17