      code = get_module_code(self, fullname, &ispackage, &modpath);
      if (code == NULL)
          goto error;
-@@ -1378,11 +1530,27 @@ get_module_code(ZipImporter *self, PyObject *fullname,
+@@ -1369,6 +1521,40 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
+     return code;
+ }
+ 
++/* Convert /path/to/__pycache/foo.pyc into /path/to/foo.pyc for
++ * compatibility reasons. Neither pkgutil nor pkg_resources will work
++ * with __pycache__ path at the moment. */
++static PyObject *
++strip_pycache_from_path(PyObject *path)
++{
++    wchar_t *s, *sub, *sub2;
++    PyObject *result = NULL, *newpath;
++
++    s = PyUnicode_AsWideCharString(path, NULL);
++    if (s == NULL)
++        return NULL;
++
++    sub = wcsstr(s, L"__pycache__");
++    if (sub == NULL) {
++        Py_INCREF(path);
++        result = path;
++        goto exit;
++    }
++
++    sub2 = sub + wcslen(L"__pycache__");
++    wmemmove(sub, sub2 + 1, wcslen(sub2) + 1);
++
++    newpath = PyUnicode_FromWideChar(s, wcslen(s));
++    if (newpath == NULL)
++        goto exit;
++
++    result = newpath;
++
++exit:
++    PyMem_Free(s);
++    return result;
++}
++
+ /* Get the code object associated with the module specified by
+    'fullname'. */
+ static PyObject *
+@@ -1378,11 +1564,25 @@ get_module_code(ZipImporter *self, PyObject *fullname,
      PyObject *code = NULL, *toc_entry, *subname;
      PyObject *path, *fullpath = NULL;
      struct st_zip_searchorder *zso;

diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index a54e947..5609764 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -624,6 +624,9 @@ def get_data(package, resource):
     # signature - an os.path format "filename" starting with the dirname of
     # the package's __file__
     parts = resource.split('/')
-    parts.insert(0, os.path.dirname(mod.__file__))
+    prefix = os.path.dirname(mod.__file__)
+    if os.path.basename(prefix) == '__pycache__':
+        prefix = os.path.dirname(prefix)
+    parts.insert(0, prefix)
     resource_name = os.path.join(*parts)
     return loader.get_data(resource_name)
diff --git a/Makefile.pre.in b/Makefile.pre.in
index e19fc00..4d372e9 100644
--- a/Makefile.pre.in

+    if (toc_entry != NULL) {
+        code = get_code_from_data(self, 0, 1, mtime, toc_entry);
+        if (code != Py_None) {
+            if (code != NULL && p_modpath != NULL)
+                *p_modpath = strip_pycache_from_path(PyTuple_GetItem(toc_entry, 0));
+            *p_ispackage = 0;
+            Py_DECREF(subname);
+            return code;
