0

I have a problem importing a module: It is under this directory ./dao and the code that calls it is here ./core. Schematically represented as:

rnaspace/
 __init__.py
 core/
   __init__.py
   logger.py
 dao/
   __init__.py
   storage_configuration_reader.py

This is the error message:

Traceback (most recent call last):   File "logger.py", line 21, in <module>
    from rnaspace.dao.storage_configuration_reader import storage_configuration_reader ImportError: No module named rnaspace.dao.storage_configuration_reader

This file it is there /rnaspace/dao/storage_configuration_reader.py and in the same folder the __init__.py file as follows:

""" Package dao
    Gathers files that access to the plateform data 
"""

If I understood well this question, it should work. I think that the problem is that one is not the subdirectory of the other (or that the path is not exaclly that one), there is a way to go around it? Or need I to apply the solution to this question?

EDIT The __init__.py file of the rnaspace folder:

import rnaspace.dao.storage_configuration_reader as scr

def update_conf(conf_path, predictors_conf_dir):
    scr.update_conf(conf_path, predictors_conf_dir)
Community
  • 1
  • 1
llrs
  • 3,308
  • 35
  • 68
  • Do you have a `__init__` file in rnaspace folder? – icedtrees Feb 18 '14 at 13:42
  • Take a look at [Intra-package References](http://docs.python.org/2/tutorial/modules.html#intra-package-references) in the Python docs. – lanzz Feb 18 '14 at 13:46
  • @icedtrees Edited, I have the file. @lanzz That means that I can import my module with just `from .. import storage_configuration_reader`? – llrs Feb 18 '14 at 13:50

2 Answers2

0
from rnaspace.dao.storage_configuration_reader import storage_configuration_reader

That is wrong because there is no "storage_configuration_reader" directory in "dao" directory

This is how it should be:

from rnaspace.dao import storage_configuration_reader

EDIT:

or this way:

import rnaspace.dao.storage_configuration_reader
Aleksandar
  • 3,541
  • 4
  • 34
  • 57
  • [Here](http://docs.python.org/2/tutorial/modules.html#packages) seems that it can point directly to the file not to the directory, but I will try it – llrs Feb 18 '14 at 13:54
  • The second version doesn't work the first one neither. But I am not sure if it is a problem of the importation or from the program itself. – llrs Feb 18 '14 at 14:24
  • in that case try to remove special characters ("_") from name of your module. Also what error you get for my examples? – Aleksandar Feb 18 '14 at 14:31
  • Well this comes from [here](http://stackoverflow.com/q/21754876/2886003) is the last part of code what I am trying to repair, but the problem is on the first sections of this question. The problem is this: `test (__main__.test_athaliana) ... No handlers could be found for logger "rnaspace"` that are defined on the file it fails, to import it. The error are still: `from rnaspace.dao import storage_configuration_reader ImportError: No module named rnaspace.da` – llrs Feb 18 '14 at 14:43
0

I finally found the solution in another question, it is using the module imp.
I just needed to add the name of the module, and the absolute path where it was:

imp.load_source("storage_configuration_reader","./rnaspace/dao/storage_configuration_reader.py")
Community
  • 1
  • 1
llrs
  • 3,308
  • 35
  • 68