      path = make_filename(self->prefix, subname);
      Py_DECREF(subname);
      if (path == NULL)
-@@ -1400,7 +1568,6 @@ get_module_code(ZipImporter *self, PyObject *fullname,
+@@ -1400,7 +1600,6 @@ get_module_code(ZipImporter *self, PyObject *fullname,
                                 self->archive, (int)SEP, fullpath);
          toc_entry = PyDict_GetItem(self->files, fullpath);
          if (toc_entry != NULL) {

             int ispackage = zso->type & IS_PACKAGE;
             int isbytecode = zso->type & IS_BYTECODE;
 
@@ -1413,6 +1580,17 @@ get_module_code(ZipImporter *self, PyObject *fullname,
             Py_CLEAR(fullpath);
             if (p_ispackage != NULL)
                 *p_ispackage = ispackage;

     code = get_module_code(self, fullname, &ispackage, &modpath);
     if (code == NULL)
         goto error;
@@ -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;
