Python ConfigParser won't run from command line
Question: Python script runs successfully within IDE, but has ConfigParser error when
attempted to run via command line.

The error:

> raise NoOptionError(option, section) ConfigParser.NoOptionError: No option
> 'password' in section: 'database'

The code:

    
    
    from ConfigParser import SafeConfigParser
    
    parser = SafeConfigParser()
    parser.read('settings.ini')
    
    # sets database and API configuration from settings.ini
    
    API_KEY = parser.get('tokens','api_key')
    
    db_user = parser.get('database','user')
    db_pwd = parser.get('database','password')
    db_host = parser.get('database','host')
    db_database =  parser.get('database','database')
    

Path and Environment appear to be fine, so the issue seems to be with
ConfigParser. Any thoughts on what might be wrong? To re-iterate, the script
runs fine from within the IDE (when using Spyder, PyCharm, etc.). Environment
is pointing to Anaconda, as anticipated.

Many thanks for help.


Answer: Your import target is incorrect. The module name is "configparser" (case-
sensitive.) The IDEs you mentioned probably perform some start-up
initialization that masks the error.

