--- Theano-rel-1.0.4.orig/theano/gof/cmodule.py	2019-01-20 10:35:30.607760200 +0800
+++ Theano-rel-1.0.4/theano/gof/cmodule.py	2019-01-20 10:47:09.262721000 +0800
@@ -315,6 +315,11 @@
             warnings.filterwarnings("ignore",
                                     message="numpy.ndarray size changed")
             rval = __import__(module_name, {}, {}, [module_name])
+            # Value of rval.__file__ contains path seperator '\\' causing
+            # fullpath.startswith(rval.__file__) is false.
+            # Perhaps, it is a bug of mingw-w64 python3 __import__ function!
+            # Now, we just replace all '\\' to '/'.
+            rval.__file__ = rval.__file__.replace('\\','/')
         t1 = time.time()
         import_time += t1 - t0
         if not rval:
@@ -1641,10 +1646,10 @@
         # installation directory, in case the user defined a custom
         # installation directory.
         python_version = distutils.sysconfig.get_python_version()
-        libname = 'python' + python_version.replace('.', '')
+        libname = 'python' + python_version + '.dll'
         # Also add directory containing the Python library to the library
         # directories.
-        python_lib_dirs = [os.path.join(os.path.dirname(python_inc), 'libs')]
+        python_lib_dirs = [os.path.join(os.path.dirname(os.path.dirname(python_inc)), 'lib')]
         if "Canopy" in python_lib_dirs[0]:
             # Canopy stores libpython27.a and libmsccr90.a in this directory.
             # For some reason, these files are needed when compiling Python
