Index: django/test/client.py
===================================================================
--- django/test/client.py	(revision 9708)
+++ django/test/client.py	(working copy)
@@ -172,7 +172,8 @@
         Obtains the current session variables.
         """
         if 'django.contrib.sessions' in settings.INSTALLED_APPS:
-            engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
+            __import__(settings.SESSION_ENGINE)
+            engine = sys.modules[settings.SESSION_ENGINE]
             cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
             if cookie:
                 return engine.SessionStore(cookie.value)
@@ -374,7 +375,8 @@
         user = authenticate(**credentials)
         if user and user.is_active \
                 and 'django.contrib.sessions' in settings.INSTALLED_APPS:
-            engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
+            __import__(settings.SESSION_ENGINE)
+            engine = sys.modules[settings.SESSION_ENGINE]
 
             # Create a fake request to store login details.
             request = HttpRequest()
@@ -409,6 +411,7 @@
 
         Causes the authenticated user to be logged out.
         """
-        session = __import__(settings.SESSION_ENGINE, {}, {}, ['']).SessionStore()
+        __import__(settings.SESSION_ENGINE)
+        session = sys.modules[settings.SESSION_ENGINE].SessionStore()
         session.delete(session_key=self.cookies[settings.SESSION_COOKIE_NAME].value)
         self.cookies = SimpleCookie()
Index: django/conf/__init__.py
===================================================================
--- django/conf/__init__.py	(revision 9708)
+++ django/conf/__init__.py	(working copy)
@@ -6,7 +6,7 @@
 a list of all possible variables.
 """
 
-import os
+import sys, os
 import time     # Needed for Windows
 from django.conf import global_settings
 
@@ -89,7 +89,8 @@
         self.SETTINGS_MODULE = settings_module
 
         try:
-            mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
+            __import__(self.SETTINGS_MODULE)
+            mod = sys.modules[self.SETTINGS_MODULE]
         except ImportError, e:
             raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
 
@@ -109,7 +110,8 @@
         new_installed_apps = []
         for app in self.INSTALLED_APPS:
             if app.endswith('.*'):
-                appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__)
+                __import__(app[:-2])
+                appdir = os.path.dirname(sys.modules[app[:-2]].__file__)
                 app_subdirs = os.listdir(appdir)
                 app_subdirs.sort()
                 for d in app_subdirs:
Index: django/db/__init__.py
===================================================================
--- django/db/__init__.py	(revision 9708)
+++ django/db/__init__.py	(working copy)
@@ -1,4 +1,4 @@
-import os
+import sys, os
 from django.conf import settings
 from django.core import signals
 from django.core.exceptions import ImproperlyConfigured
@@ -13,13 +13,17 @@
     # Most of the time, the database backend will be one of the official
     # backends that ships with Django, so look there first.
     _import_path = 'django.db.backends.'
-    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
+    _mod_name = '%s%s.base' % (_import_path, settings.DATABASE_ENGINE)
+    __import__(_mod_name)
+    backend = sys.modules[_mod_name]
 except ImportError, e:
     # If the import failed, we might be looking for a database backend
     # distributed external to Django. So we'll try that next.
     try:
         _import_path = ''
-        backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
+        _mod_name = '%s.base' % settings.DATABASE_ENGINE
+        __import__(_mod_name)
+        backend = sys.modules[_mod_name]
     except ImportError, e_user:
         # The database backend wasn't found. Display a helpful error message
         # listing all possible (built-in) database backends.
Index: django/core/serializers/__init__.py
===================================================================
--- django/core/serializers/__init__.py	(revision 9708)
+++ django/core/serializers/__init__.py	(working copy)
@@ -16,6 +16,7 @@
 
 """
 
+import sys
 from django.conf import settings
 
 # Built-in serializers
@@ -35,24 +36,25 @@
 _serializers = {}
 
 def register_serializer(format, serializer_module, serializers=None):
-    """"Register a new serializer. 
-    
+    """"Register a new serializer.
+
     ``serializer_module`` should be the fully qualified module name
     for the serializer.
-    
+
     If ``serializers`` is provided, the registration will be added
     to the provided dictionary.
-    
+
     If ``serializers`` is not provided, the registration will be made
     directly into the global register of serializers. Adding serializers
     directly is not a thread-safe operation.
     """
-    module = __import__(serializer_module, {}, {}, [''])
+    __import__(serializer_module)
+    module = sys.modules[serializer_module]
     if serializers is None:
         _serializers[format] = module
     else:
         serializers[format] = module
-        
+
 def unregister_serializer(format):
     "Unregister a given serializer. This is not a thread-safe operation."
     del _serializers[format]
Index: django/core/urlresolvers.py
===================================================================
--- django/core/urlresolvers.py	(revision 9708)
+++ django/core/urlresolvers.py	(working copy)
@@ -7,7 +7,7 @@
     (view_function, function_args, function_kwargs)
 """
 
-import re
+import sys, re
 
 from django.http import Http404
 from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
@@ -54,7 +54,8 @@
             lookup_view = lookup_view.encode('ascii')
             mod_name, func_name = get_mod_func(lookup_view)
             if func_name != '':
-                lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
+                __import__(mod_name)
+                lookup_view = getattr(sys.modules[mod_name], func_name)
                 if not callable(lookup_view):
                     raise AttributeError("'%s.%s' is not a callable." % (mod_name, func_name))
         except (ImportError, AttributeError):
@@ -195,7 +196,8 @@
         try:
             return self._urlconf_module
         except AttributeError:
-            self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
+            __import__(self.urlconf_name)
+            self._urlconf_module = sys.modules[self.urlconf_name]
             return self._urlconf_module
     urlconf_module = property(_get_urlconf_module)
 
@@ -207,7 +209,8 @@
         callback = getattr(self.urlconf_module, 'handler%s' % view_type)
         mod_name, func_name = get_mod_func(callback)
         try:
-            return getattr(__import__(mod_name, {}, {}, ['']), func_name), {}
+            __import__(mod_name)
+            return getattr(sys.modules[mod_name], func_name), {}
         except (ImportError, AttributeError), e:
             raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e))
 
Index: django/core/handlers/base.py
===================================================================
--- django/core/handlers/base.py	(revision 9708)
+++ django/core/handlers/base.py	(working copy)
@@ -35,7 +35,8 @@
                 raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path
             mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
             try:
-                mod = __import__(mw_module, {}, {}, [''])
+                __import__(mw_module)
+                mod = sys.modules[mw_module]
             except ImportError, e:
                 raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)
             try:
Index: django/core/files/storage.py
===================================================================
--- django/core/files/storage.py	(revision 9708)
+++ django/core/files/storage.py	(working copy)
@@ -1,4 +1,4 @@
-import os
+import sys, os
 import errno
 import urlparse
 
@@ -219,7 +219,8 @@
         raise ImproperlyConfigured("%s isn't a storage module." % import_path)
     module, classname = import_path[:dot], import_path[dot+1:]
     try:
-        mod = __import__(module, {}, {}, [''])
+        __import__(module)
+        mod = sys.modules[module]
     except ImportError, e:
         raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e))
     try:
Index: django/core/cache/__init__.py
===================================================================
--- django/core/cache/__init__.py	(revision 9708)
+++ django/core/cache/__init__.py	(working copy)
@@ -15,6 +15,7 @@
 See docs/cache.txt for information on the public API.
 """
 
+import sys
 from cgi import parse_qsl
 from django.conf import settings
 from django.core import signals
@@ -49,9 +50,12 @@
         host = host[:-1]
 
     if scheme in BACKENDS:
-        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [''])
+        modname = 'django.core.cache.backends.%s' % BACKENDS[scheme]
+        __import__(modname)
+        module = sys.modules[modname]
     else:
-        module = __import__(scheme, {}, {}, [''])
+        __import__(scheme)
+        module = sys.modules[scheme]
     return getattr(module, 'CacheClass')(host, params)
 
 cache = get_cache(settings.CACHE_BACKEND)
Index: django/core/management/commands/flush.py
===================================================================
--- django/core/management/commands/flush.py	(revision 9708)
+++ django/core/management/commands/flush.py	(working copy)
@@ -23,7 +23,7 @@
         # dispatcher events.
         for app_name in settings.INSTALLED_APPS:
             try:
-                __import__(app_name + '.management', {}, {}, [''])
+                __import__(app_name + '.management')
             except ImportError:
                 pass
 
Index: django/core/management/commands/syncdb.py
===================================================================
--- django/core/management/commands/syncdb.py	(revision 9708)
+++ django/core/management/commands/syncdb.py	(working copy)
@@ -30,7 +30,7 @@
         # dispatcher events.
         for app_name in settings.INSTALLED_APPS:
             try:
-                __import__(app_name + '.management', {}, {}, [''])
+                __import__(app_name + '.management')
             except ImportError, exc:
                 # This is slightly hackish. We want to ignore ImportErrors
                 # if the "management" module itself is missing -- but we don't
Index: django/core/management/__init__.py
===================================================================
--- django/core/management/__init__.py	(revision 9708)
+++ django/core/management/__init__.py	(working copy)
@@ -104,11 +104,10 @@
         # Find the project directory
         try:
             from django.conf import settings
+            __import__(settings.SETTINGS_MODULE)
             project_directory = setup_environ(
-                __import__(
-                    settings.SETTINGS_MODULE, {}, {},
-                    (settings.SETTINGS_MODULE.split(".")[-1],)
-                ), settings.SETTINGS_MODULE
+                    sys.modules[settings.SETTINGS_MODULE],
+                    settings.SETTINGS_MODULE
             )
         except (AttributeError, EnvironmentError, ImportError):
             project_directory = None
@@ -313,7 +312,8 @@
     project_name = os.path.basename(project_directory)
     settings_name = os.path.splitext(settings_filename)[0]
     sys.path.append(os.path.join(project_directory, os.pardir))
-    project_module = __import__(project_name, {}, {}, [''])
+    __import__(project_name)
+    project_module = sys.modules[project_name]
     sys.path.pop()
 
     # Set DJANGO_SETTINGS_MODULE appropriately.
Index: django/templatetags/__init__.py
===================================================================
--- django/templatetags/__init__.py	(revision 9708)
+++ django/templatetags/__init__.py	(working copy)
@@ -1,3 +1,4 @@
+import sys
 from django.conf import settings
 
 for a in settings.INSTALLED_APPS:
@@ -2,3 +3,5 @@
     try:
-        __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__)
+        modname = a + '.templatetags'
+        __import__(modname)
+        __path__.extend(sys.modules[modname].__path__)
     except ImportError:
Index: django/views/i18n.py
===================================================================
--- django/views/i18n.py	(revision 9708)
+++ django/views/i18n.py	(working copy)
@@ -2,7 +2,7 @@
 from django.utils.translation import check_for_language, activate, to_locale, get_language
 from django.utils.text import javascript_quote
 from django.conf import settings
-import os
+import sys, os
 import gettext as gettext_module
 
 def set_language(request):
@@ -128,7 +128,8 @@
     paths = []
     # first load all english languages files for defaults
     for package in packages:
-        p = __import__(package, {}, {}, [''])
+        __import__(package)
+        p = sys.modules[package]
         path = os.path.join(os.path.dirname(p.__file__), 'locale')
         paths.append(path)
         try:
Index: django/contrib/comments/__init__.py
===================================================================
--- django/contrib/comments/__init__.py	(revision 9708)
+++ django/contrib/comments/__init__.py	(working copy)
@@ -1,3 +1,4 @@
+import sys
 from django.conf import settings
 from django.core import urlresolvers
 from django.core.exceptions import ImproperlyConfigured
@@ -17,7 +18,8 @@
 
     # Try to import the package
     try:
-        package = __import__(comments_app, '', '', [''])
+        __import__(comments_app)
+        package = sys.modules[comments_app]
     except ImportError:
         raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
                                    "a non-existing package.")
Index: django/contrib/admin/views/template.py
===================================================================
--- django/contrib/admin/views/template.py	(revision 9708)
+++ django/contrib/admin/views/template.py	(working copy)
@@ -1,3 +1,4 @@
+import sys
 from django import template, forms
 from django.contrib.admin.views.decorators import staff_member_required
 from django.template import loader
@@ -15,7 +16,8 @@
     # get a dict of {site_id : settings_module} for the validator
     settings_modules = {}
     for mod in settings.ADMIN_FOR:
-        settings_module = __import__(mod, {}, {}, [''])
+        __import__(mod)
+        settings_module = sys.modules[mod]
         settings_modules[settings_module.SITE_ID] = settings_module
     site_list = Site.objects.in_bulk(settings_modules.keys()).values()
     if request.POST:
Index: django/contrib/admindocs/views.py
===================================================================
--- django/contrib/admindocs/views.py	(revision 9708)
+++ django/contrib/admindocs/views.py	(working copy)
@@ -11,7 +11,7 @@
 from django.contrib.sites.models import Site
 from django.utils.translation import ugettext as _
 from django.utils.safestring import mark_safe
-import inspect, os, re
+import sys, inspect, os, re
 
 # Exclude methods starting with these strings from documentation
 MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_')
@@ -114,13 +114,17 @@
         return missing_docutils_page(request)
 
     if settings.ADMIN_FOR:
-        settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR]
+        settings_modules = []
+        for m in settings.ADMIN_FOR:
+            __import__(m)
+            settings_modules.append(sys.modules[m])
     else:
         settings_modules = [settings]
 
     views = []
     for settings_mod in settings_modules:
-        urlconf = __import__(settings_mod.ROOT_URLCONF, {}, {}, [''])
+        __import__(settings_mod.ROOT_URLCONF)
+        urlconf = sys.modules[settings_mod.ROOT_URLCONF]
         view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
         if Site._meta.installed:
             site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
@@ -146,7 +150,8 @@
 
     mod, func = urlresolvers.get_mod_func(view)
     try:
-        view_func = getattr(__import__(mod, {}, {}, ['']), func)
+        __import__(mod)
+        view_func = getattr(sys.modules[mod], func)
     except (ImportError, AttributeError):
         raise Http404
     title, body, metadata = utils.parse_docstring(view_func.__doc__)
@@ -257,7 +262,8 @@
 def template_detail(request, template):
     templates = []
     for site_settings_module in settings.ADMIN_FOR:
-        settings_mod = __import__(site_settings_module, {}, {}, [''])
+        __import__(site_settings_module)
+        settings_mod = sys.modules[site_settings_module]
         if Site._meta.installed:
             site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
         else:
Index: django/contrib/sessions/middleware.py
===================================================================
--- django/contrib/sessions/middleware.py	(revision 9708)
+++ django/contrib/sessions/middleware.py	(working copy)
@@ -1,4 +1,4 @@
-import time
+import sys, time
 
 from django.conf import settings
 from django.utils.cache import patch_vary_headers
@@ -6,7 +6,9 @@
 
 class SessionMiddleware(object):
     def process_request(self, request):
-        engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
+        # FIXME: __import__ on EVERY request?! Move to __init__
+        __import__(settings.SESSION_ENGINE)
+        engine = sys.modules[settings.SESSION_ENGINE]
         session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
         request.session = engine.SessionStore(session_key)
 
Index: django/template/__init__.py
===================================================================
--- django/template/__init__.py	(revision 9708)
+++ django/template/__init__.py	(working copy)
@@ -48,7 +48,7 @@
 >>> t.render(c)
 u'<html></html>'
 """
-import re
+import sys, re
 from inspect import getargspec
 from django.conf import settings
 from django.template.context import Context, RequestContext, ContextPopException
@@ -934,7 +934,8 @@
     lib = libraries.get(module_name, None)
     if not lib:
         try:
-            mod = __import__(module_name, {}, {}, [''])
+            __import__(module_name)
+            mod = sys.modules[module_name]
         except ImportError, e:
             raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e))
         try:
Index: tests/regressiontests/dynamic_imports/__init__.py
===================================================================
Index: tests/regressiontests/dynamic_imports/tests.py
===================================================================
--- tests/regressiontests/dynamic_imports/tests.py	(revision 0)
+++ tests/regressiontests/dynamic_imports/tests.py	(revision 0)
@@ -0,0 +1,11 @@
+__test__ = {'API_TESTS': """
+>>> import sys
+>>> import os
+>>> mod_name = os.environ['DJANGO_SETTINGS_MODULE']
+>>> __import__(mod_name)
+>>> mod = sys.modules[mod_name]
+>>> from django.core.management import setup_environ
+>>> d = setup_environ(mod)
+>>> [k for k in sys.modules if k.endswith('.') or '..' in k]
+[]
+"""}
