Index: installers/setup_exe.py
===================================================================
--- installers/setup_exe.py	(revision 92df9cbd8c317f55f6ef521bbea72ea7b87ea8ab)
+++ installers/setup_exe.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -46,5 +46,4 @@
 sys.path.insert(0, build_path)
 
-from sas.sasview import local_config
 from installer_generator import generate_installer
 
@@ -74,4 +73,6 @@
           sys.exc_value)
 
+from sas import get_local_config
+local_config = get_local_config()
 
 # Solution taken from here: http://www.py2exe.org/index.cgi/win32com.shell
Index: installers/setup_mac.py
===================================================================
--- installers/setup_mac.py	(revision 67d8b1b3e03ac53dd3f64c742eeaa9b5a577ed43)
+++ installers/setup_mac.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -45,5 +45,6 @@
 import macholib_patch
 
-from sas.sasview import local_config
+from sas import get_local_config
+local_config = get_local_config()
 
 ICON = local_config.SetupIconFile_mac
Index: src/sas/__init__.py
===================================================================
--- src/sas/__init__.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/__init__.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -0,0 +1,57 @@
+__all__ = ['get_app_dir', 'get_user_dir',
+           'get_local_config', 'get_custom_config']
+
+_APP_DIR = None
+def get_app_dir():
+    """
+    The directory where the sasview application is found.
+
+    Returns the path to sasview if running in place or installed with setup.
+    If the application is frozen, returns the parent directory of the
+    application resources such as test files and images.
+    """
+    global _APP_DIR
+    if not _APP_DIR:
+        from ._config import find_app_dir
+        _APP_DIR = find_app_dir()
+    return _APP_DIR
+
+_USER_DIR = None
+def get_user_dir():
+    """
+    The directory where the per-user configuration is stored.
+
+    Returns ~/.sasview, creating it if it does not already exist.
+    """
+    global _USER_DIR
+    if not _USER_DIR:
+        from ._config import make_user_dir
+        _USER_DIR = make_user_dir()
+    return _USER_DIR
+
+def make_custom_config_path():
+    from ._config import make_custom_config_path as _make_path
+    return _make_path(get_user_dir())
+
+_CUSTOM_CONFIG = None
+def get_custom_config():
+    """
+    Setup the custom config dir and cat file
+    """
+    global _CUSTOM_CONFIG
+    if not _CUSTOM_CONFIG:
+        from ._config import setup_custom_config
+        _CUSTOM_CONFIG = setup_custom_config(get_app_dir(), get_user_dir())
+    return _CUSTOM_CONFIG
+
+
+_LOCAL_CONFIG = None
+def get_local_config():
+    """
+    Loads the local config file.
+    """
+    global _LOCAL_CONFIG
+    if not _LOCAL_CONFIG:
+        from ._config import load_local_config
+        _LOCAL_CONFIG = load_local_config(get_app_dir())
+    return _LOCAL_CONFIG
Index: src/sas/_config.py
===================================================================
--- src/sas/_config.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
+++ src/sas/_config.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -0,0 +1,119 @@
+# Setup and find Custom config dir
+from __future__ import print_function
+
+import sys
+import os
+from os.path import exists, expanduser, dirname, realpath, join as joinpath
+import logging
+import shutil
+
+from sasmodels.custom import load_module_from_path
+
+logger = logging.getLogger(__name__)
+
+def dirn(path, n):
+    """
+    Return the directory n up from the current path
+    """
+    path = realpath(path)
+    for _ in range(n):
+        path = dirname(path)
+    return path
+
+def find_app_dir():
+    """
+    Locate the parent directory of the sasview resources.  For the normal
+    application this will be the directory containing sasview.py.  For the
+    frozen application this will be the path where the resources are installed.
+    """
+    # We are starting out with the following info:
+    #     __file__ = .../sas/__init__.pyc
+    # Check if the path .../sas/sasview exists, and use it as the
+    # app directory.  This will only be the case if the app is not frozen.
+    path = joinpath(dirname(__file__), 'sasview')
+    if exists(path):
+        return path
+
+    # If we are running frozen, then root is a parent directory
+    if sys.platform == 'darwin':
+        # Here is the path to the file on the mac:
+        #     .../Sasview.app/Contents/Resources/lib/python2.7/site-packages.zip/sas/__init__.pyc
+        # We want the path to the Resources directory.
+        path = dirn(__file__, 5)
+    elif os.name == 'nt':
+        # Here is the path to the file on windows:
+        #     ../Sasview/library.zip/sas/__init__.pyc
+        # We want the path to the Sasview directory.
+        path = dirn(__file__, 3)
+    else:
+        raise RuntimeError("Couldn't find the app directory")
+    return path
+
+def make_user_dir():
+    """
+    Create the user directory ~/.sasview if it doesn't already exist.
+    """
+    path = joinpath(expanduser("~"),'.sasview')
+    if not exists(path):
+        os.mkdir(path)
+    return path
+
+def load_local_config(app_dir):
+    logger = logging.getLogger(__name__)
+    filename = 'local_config.py'
+    path = os.path.join(app_dir, filename)
+    try:
+        module = load_module_from_path('sas.local_config', path)
+        logger.info("GuiManager loaded %s", path)
+        return module
+    except Exception as exc:
+        logger.critical("Error loading %s: %s", path, exc)
+        sys.exit()
+
+def make_custom_config_path(user_dir):
+    """
+    The location of the cusstom config file.
+
+    Returns ~/.sasview/config/custom_config.py
+    """
+    dirname = os.path.join(user_dir, 'config')
+    # If the directory doesn't exist, create it
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
+    path = os.path.join(dirname, "custom_config.py")
+    return path
+
+def setup_custom_config(app_dir, user_dir):
+    path = make_custom_config_path(user_dir)
+    if not os.path.isfile(path):
+        try:
+            # if the custom config file does not exist, copy the default from
+            # the app dir
+            shutil.copyfile(os.path.join(app_dir, "custom_config.py"), path)
+        except Exception:
+            logger.error("Could not copy default custom config.")
+
+    #Adding SAS_OPENCL if it doesn't exist in the config file
+    # - to support backcompability
+    if not "SAS_OPENCL" in open(path).read():
+        try:
+            open(config_file, "a+").write("SAS_OPENCL = \"None\"\n")
+        except Exception:
+            logger.error("Could not update custom config with SAS_OPENCL.")
+
+    custom_config = load_custom_config(path)
+    return custom_config
+
+
+def load_custom_config(path):
+    if os.path.exists(path):
+        try:
+            module = load_module_from_path('sas.custom_config', path)
+            logger.info("GuiManager loaded %s", path)
+            return module
+        except Exception as exc:
+            logger.error("Error loading %s: %s", path, exc)
+
+    from sas.sasview import custom_config
+    logger.info("GuiManager custom_config defaults to sas.sasview.custom_config")
+    return custom_config
Index: src/sas/sascalc/fit/models.py
===================================================================
--- src/sas/sascalc/fit/models.py	(revision 9706d88b71e719f590147b9914149630bce2f1d2)
+++ src/sas/sascalc/fit/models.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -15,5 +15,5 @@
 from sasmodels.sasview_model import load_custom_model, load_standard_models
 
-from sas.sasgui import get_user_dir
+from sas import get_user_dir
 
 # Explicitly import from the pluginmodel module so that py2exe
Index: src/sas/sasgui/__init__.py
===================================================================
--- src/sas/sasgui/__init__.py	(revision c6bdb3b56ff2c1bf95baa3241ca1df10d74a79d7)
+++ src/sas/sasgui/__init__.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -1,85 +1,0 @@
-import sys
-import os
-from os.path import exists, expanduser, dirname, realpath, join as joinpath
-
-
-def dirn(path, n):
-    path = realpath(path)
-    for _ in range(n):
-        path = dirname(path)
-    return path
-
-# Set up config directories
-def make_user_folder():
-    path = joinpath(expanduser("~"),'.sasview')
-    if not exists(path):
-        os.mkdir(path)
-    return path
-
-
-def find_app_folder():
-    # We are starting out with the following info:
-    #     __file__ = .../sas/sasgui/__init__.pyc
-    # Check if the sister path .../sas/sasview exists, and use it as the
-    # app directory.  This will only be the case if the app is not frozen.
-    path = joinpath(dirn(__file__, 2), 'sasview')
-    if exists(path):
-        return path
-
-    # If we are running frozen, then root is a parent directory
-    if sys.platform == 'darwin':
-        # Here is the path to the file on the mac:
-        #     .../Sasview.app/Contents/Resources/lib/python2.7/site-packages.zip/sas/sasgui/__init__.pyc
-        # We want the path to the Resources directory.
-        path = dirn(__file__, 6)
-    elif os.name == 'nt':
-        # Here is the path to the file on windows:
-        #     ../Sasview/library.zip/sas/sasgui/__init__.pyc
-        # We want the path to the Sasview directory.
-        path = dirn(__file__, 4)
-    else:
-        raise RuntimeError("Couldn't find the app directory")
-    return path
-
-USER_FOLDER = make_user_folder()
-APP_FOLDER = find_app_folder()
-
-
-def get_app_dir():
-    return APP_FOLDER
-
-def get_user_dir():
-    return USER_FOLDER
-
-def get_custom_config_path():
-    dirname = os.path.join(get_user_dir(), 'config')
-    # If the directory doesn't exist, create it
-    if not os.path.exists(dirname):
-        os.makedirs(dirname)
-    path = os.path.join(dirname, "custom_config.py")
-    return path
-
-_config_cache = None
-def get_local_config():
-    global _config_cache
-    if not _config_cache:
-        _config_cache = _load_config()
-    return _config_cache
-
-def _load_config():
-    import os
-    import sys
-    import logging
-    from sasmodels.custom import load_module_from_path
-
-    logger = logging.getLogger(__name__)
-    dirname = get_app_dir()
-    filename = 'local_config.py'
-    path = os.path.join(dirname, filename)
-    try:
-        module = load_module_from_path('sas.sasgui.local_config', path)
-        logger.info("GuiManager loaded %s", path)
-        return module
-    except Exception as exc:
-        logger.critical("Error loading %s: %s", path, exc)
-        sys.exit()
Index: src/sas/sasgui/guiframe/CategoryInstaller.py
===================================================================
--- src/sas/sasgui/guiframe/CategoryInstaller.py	(revision 6e50a8d413a9ee39f4e97836486b9f343ad3f470)
+++ src/sas/sasgui/guiframe/CategoryInstaller.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -15,5 +15,5 @@
 from collections import defaultdict, OrderedDict
 
-from sas.sasgui import get_user_dir
+from sas import get_user_dir
 
 USER_FILE = 'categories.json'
Index: src/sas/sasgui/guiframe/aboutbox.py
===================================================================
--- src/sas/sasgui/guiframe/aboutbox.py	(revision 959eb0181ad06828a748f04512f953aad5b31659)
+++ src/sas/sasgui/guiframe/aboutbox.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -25,5 +25,5 @@
 import os
 
-from sas.sasgui import get_local_config
+from sas import get_local_config
 config = get_local_config()
 
Index: src/sas/sasgui/guiframe/acknowledgebox.py
===================================================================
--- src/sas/sasgui/guiframe/acknowledgebox.py	(revision 74c8cd08df1c5d3f23477827c0f272e88bbbea9d)
+++ src/sas/sasgui/guiframe/acknowledgebox.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -13,5 +13,5 @@
 from wx.lib.expando import ExpandoTextCtrl
 
-from sas.sasgui import get_local_config
+from sas import get_local_config
 config = get_local_config()
 
Index: src/sas/sasgui/guiframe/config.py
===================================================================
--- src/sas/sasgui/guiframe/config.py	(revision d9089328dec4c154a6bac2735e52b5e6fb3c8af2)
+++ src/sas/sasgui/guiframe/config.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -145,7 +145,4 @@
 UPDATE_TIMEOUT = 2
 
-#OpenCL option
-SAS_OPENCL = None
-
 # Time out for updating sasview
 UPDATE_TIMEOUT = 2
Index: c/sas/sasgui/guiframe/customdir.py
===================================================================
--- src/sas/sasgui/guiframe/customdir.py	(revision c6bdb3b56ff2c1bf95baa3241ca1df10d74a79d7)
+++ 	(revision )
@@ -1,59 +1,0 @@
-# Setup and find Custom config dir
-from __future__ import print_function
-
-import os.path
-import logging
-import shutil
-
-from sasmodels.custom import load_module_from_path
-
-from sas.sasgui import get_custom_config_path, get_app_dir
-
-logger = logging.getLogger(__name__)
-
-_config_cache = None
-def setup_custom_config():
-    """
-    Setup the custom config dir and cat file
-    """
-    global _config_cache
-    if not _config_cache:
-        _config_cache = _setup_custom_config()
-    return _config_cache
-
-
-def _setup_custom_config():
-    path = get_custom_config_path()
-    if not os.path.isfile(path):
-        try:
-            # if the custom config file does not exist, copy the default from
-            # the app dir
-            shutil.copyfile(os.path.join(get_app_dir(), "custom_config.py"),
-                            path)
-        except Exception:
-            logger.error("Could not copy default custom config.")
-
-    #Adding SAS_OPENCL if it doesn't exist in the config file
-    # - to support backcompability
-    if not "SAS_OPENCL" in open(path).read():
-        try:
-            open(config_file, "a+").write("SAS_OPENCL = \"None\"\n")
-        except Exception:
-            logger.error("Could not update custom config with SAS_OPENCL.")
-
-    custom_config = _load_config(path)
-    return custom_config
-
-
-def _load_config(path):
-    if os.path.exists(path):
-        try:
-            module = load_module_from_path('sas.sasview.custom_config', path)
-            logger.info("GuiManager loaded %s", path)
-            return module
-        except Exception as exc:
-            logger.error("Error loading %s: %s", path, exc)
-
-    from sas.sasview import custom_config
-    logger.info("GuiManager custom_config defaults to sas.sasview.custom_config")
-    return custom_config
Index: src/sas/sasgui/guiframe/data_panel.py
===================================================================
--- src/sas/sasgui/guiframe/data_panel.py	(revision c6bdb3b56ff2c1bf95baa3241ca1df10d74a79d7)
+++ src/sas/sasgui/guiframe/data_panel.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -33,5 +33,5 @@
 from sas.sasgui.guiframe.local_perspectives.plotting.SimplePlot \
     import PlotFrame as QucikPlotDialog
-from sas.sasgui import get_local_config
+from sas import get_local_config
 
 config = get_local_config()
Index: src/sas/sasgui/guiframe/documentation_window.py
===================================================================
--- src/sas/sasgui/guiframe/documentation_window.py	(revision 2746eab3d2fd36206508d585c8b2ed061fabce96)
+++ src/sas/sasgui/guiframe/documentation_window.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -27,5 +27,5 @@
     WX_SUPPORTS_HTML2 = False
 
-from sas.sasgui import get_app_dir
+from sas import get_app_dir
 
 # Don't use wx html renderer on windows.
Index: src/sas/sasgui/guiframe/gui_manager.py
===================================================================
--- src/sas/sasgui/guiframe/gui_manager.py	(revision 2f22db96dce134a5ac8f4dba0b22c4df370c5431)
+++ src/sas/sasgui/guiframe/gui_manager.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -28,5 +28,5 @@
 from matplotlib import _pylab_helpers
 
-from sas.sasgui import get_local_config, get_app_dir, get_user_dir
+from sas import get_local_config, get_custom_config, get_app_dir, get_user_dir
 from sas.sasgui.guiframe.events import EVT_CATEGORY
 from sas.sasgui.guiframe.events import EVT_STATUS
@@ -47,5 +47,4 @@
 from sas.sascalc.dataloader.loader import Loader
 from sas.sasgui.guiframe.proxy import Connection
-from sas.sasgui.guiframe.customdir import setup_custom_config
 
 logger = logging.getLogger(__name__)
@@ -53,5 +52,5 @@
 
 config = get_local_config()
-custom_config = setup_custom_config()
+custom_config = get_custom_config()
 
 # read some constants from config
@@ -63,5 +62,4 @@
 SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT
 SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME
-SAS_OPENCL = config.SAS_OPENCL
 if not WELCOME_PANEL_ON:
     WELCOME_PANEL_SHOW = False
@@ -138,8 +136,4 @@
         PARENT_FRAME = wx.Frame
         CHILD_FRAME = wx.Frame
-
-#Initiliaze enviromental variable with custom setting but only if variable not set
-if SAS_OPENCL and not "SAS_OPENCL" in os.environ:
-    os.environ["SAS_OPENCL"] = SAS_OPENCL
 
 class ViewerFrame(PARENT_FRAME):
Index: src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
===================================================================
--- src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py	(revision dcb91cf83e474bdbe1c788d87690ca5f5e7841cb)
+++ src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -10,8 +10,9 @@
 logger = logging.getLogger(__name__)
 
+from sas import get_local_config
+
 from sas.sascalc.dataloader.loader import Loader
 from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException
 
-from sas.sasgui import get_local_config
 from sas.sasgui.guiframe.plugin_base import PluginBase
 from sas.sasgui.guiframe.events import StatusEvent
Index: src/sas/sasgui/guiframe/startup_configuration.py
===================================================================
--- src/sas/sasgui/guiframe/startup_configuration.py	(revision 7432acb919f4013119ca918a73350297e0d4c93f)
+++ src/sas/sasgui/guiframe/startup_configuration.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -13,5 +13,5 @@
 import wx
 
-from sas.sasgui import get_custom_config_path
+from sas import make_custom_config_path
 from sas.sasgui.guiframe.events import StatusEvent
 from sas.sasgui.guiframe.gui_style import GUIFRAME
@@ -194,5 +194,5 @@
         Write custom configuration
         """
-        path = get_custom_config_path()
+        path = make_custom_config_path()
         with open(path, 'w') as out_f:
             out_f.write("#Application appearance custom configuration\n")
Index: src/sas/sasview/local_config.py
===================================================================
--- src/sas/sasview/local_config.py	(revision c6bdb3b56ff2c1bf95baa3241ca1df10d74a79d7)
+++ src/sas/sasview/local_config.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -145,7 +145,4 @@
 UPDATE_TIMEOUT = 2
 
-#OpenCL option
-SAS_OPENCL = None
-
 # Time out for updating sasview
 UPDATE_TIMEOUT = 2
Index: src/sas/sasview/sasview.py
===================================================================
--- src/sas/sasview/sasview.py	(revision 169314183480fb2569cb35a048869a2ac32476a0)
+++ src/sas/sasview/sasview.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -20,4 +20,6 @@
 reload(sys)
 sys.setdefaultencoding("iso-8859-1")
+
+import sas
 
 APP_NAME = 'SasView'
@@ -171,8 +173,7 @@
 
 
-def setup_mpl(backend='WXAgg'):
-    import sas.sasgui
+def setup_mpl(backend=None):
     # Always use private .matplotlib setup to avoid conflicts with other
-    mplconfigdir = os.path.join(sas.sasgui.get_user_dir(), '.matplotlib')
+    mplconfigdir = os.path.join(sas.get_user_dir(), '.matplotlib')
     if not os.path.exists(mplconfigdir):
         os.mkdir(mplconfigdir)
@@ -192,11 +193,11 @@
     Prepare sasmodels for running within sasview.
     """
-    import sas.sasgui
     # Set SAS_MODELPATH so sasmodels can find our custom models
-    plugin_dir = os.path.join(sas.sasgui.get_user_dir(), PLUGIN_MODEL_DIR)
+    plugin_dir = os.path.join(sas.get_user_dir(), PLUGIN_MODEL_DIR)
     os.environ['SAS_MODELPATH'] = plugin_dir
-    # TODO: SAS_OPENCL flag belongs in setup_sasmodels
-    # this will require restructuring of the config management so that it
-    # can occur outside of sasgui.
+    #Initiliaze enviromental variable with custom setting but only if variable not set
+    SAS_OPENCL = sas.get_custom_config().SAS_OPENCL
+    if SAS_OPENCL and "SAS_OPENCL" not in os.environ:
+        os.environ["SAS_OPENCL"] = SAS_OPENCL
 
 def run_gui():
@@ -207,5 +208,5 @@
     freeze_support()
     setup_logging()
-    setup_mpl()
+    setup_mpl(backend='WXAgg')
     setup_sasmodels()
     setup_wx()
@@ -217,5 +218,8 @@
     freeze_support()
     setup_logging()
-    setup_mpl(backend='Agg')
+    # Use default matplotlib backend on mac/linux, but wx on windows.
+    # The problem on mac is that the wx backend requires pythonw.  On windows
+    # we are sure to wx since it is the shipped with the app.
+    setup_mpl(backend='WXAgg' if os.name == 'nt' else None)
     setup_sasmodels()
     if len(sys.argv) == 1:
Index: src/sas/sasview/welcome_panel.py
===================================================================
--- src/sas/sasview/welcome_panel.py	(revision d66dbcc8e869f27ec52bbe59173bde142f2c4a60)
+++ src/sas/sasview/welcome_panel.py	(revision b963b2066d6a76fe5073000c5a596a6fd0130ac4)
@@ -10,5 +10,5 @@
 from wx.lib.scrolledpanel import ScrolledPanel
 
-from sas.sasgui import get_local_config
+from sas import get_local_config
 from sas.sasgui.guiframe.panel_base import PanelBase
 config = get_local_config()
