Pyconfigini: ImportError: No module named lib.pyconfigini
Question: I have been looking for an ini parse with inheritance support such as
Zend_Config_Ini, So I found pyconfigini
(https://bitbucket.org/maascamp/pyconfigini)

I have the following project structure:

  * app 
    * __ init __.py
    * settings.py
  * lib 
    * __ init __.py
    * pyconfigini.py

I copied pyconfigini.py module source
here(https://bitbucket.org/maascamp/pyconfigini) to lib/pyconfigini.py and In
my setting module (app/setting.py) I coded:

    
    
    import os
    from lib.pyconfigini import parse_ini
    PROJECT_DIR = os.path.join( os.path.dirname(__file__), '../');
    APP_ENV = os.getenv('APP_ENV','development')
    config = parse_ini(os.path.abspath(os.path.join(PROJECT_DIR,"config.ini")), APP_ENV)
    print config.nome
    

However when I run it in command line I get this error

    
    
    > python settings.py
    Traceback (most recent call last):
      File "settings.py", line 7, in <module>
        from lib.pyconfigini import parse_ini
    ImportError: No module named lib.pyconfigini
    

Why I am getting this error? How could I fix it?


Answer: The problem is that you're running

    
    
    python setting.py
    

from `app/` directory (which at the moment of script start becomes `current
working directory`) . Python looks for modules in directories that are listed
in **PYTHONPATH** environment variable (you can get access to it from Python
code via `sys.path` variable).

This list of directories contains standard `site-packages`, `dist-packages`,
etc. directories and you `current working directory` \- a directory, from
which you're trying to run your script.

As you can see from the above information, `lib` package cannot be found as it
doesn't exist in directories listed in `sys.path`.

So, I advice you to change entry point script location to you root directory,
where `app` and `lib` packages are located.

But if you wan't to test `settings.py` module for some reason running it
directly, you can define your PYTHONPATH manually, running your script e.g.
such way:

    
    
    PYTHONPATH="../lib" python ./settings.py
    

This will patch your PYTHONPATH with needed `lib` directory.

Another way to run your app is to put `lib` package inside `app/` directory.

