diff --git a/m4/python.m4 b/m4/python.m4
index cb38b05..530e378 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -43,13 +43,17 @@ AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
 [AC_REQUIRE([AM_PATH_PYTHON])
 AC_MSG_CHECKING(for headers required to compile python extensions)
 dnl deduce PYTHON_INCLUDES
-py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
-py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
+am_python_print_includes="\
+from distutils import sysconfig as sc
+incldirs = [[]]
+
+for d in sc.get_config_var('INCLDIRSTOMAKE').split():
+    incldirs.append('-I' + d)
+
+print(' '.join(incldirs))
+"
 if test "x$PYTHON_INCLUDES" == x; then
-  PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
-  if test "$py_prefix" != "$py_exec_prefix"; then
-    PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
-  fi
+  PYTHON_INCLUDES=`$PYTHON -c "$am_python_print_includes"`
 fi
 AC_SUBST(PYTHON_INCLUDES)
 dnl check if the headers exist:
@@ -70,12 +74,19 @@ AC_DEFUN([AM_CHECK_PYTHON_LIBS],
 [AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
 AC_MSG_CHECKING(for libraries required to embed python)
 dnl deduce PYTHON_LIBS
-py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
+am_python_print_libs="\
+from distutils import sysconfig as sc
+libs = '-L' + sc.get_config_var('LIBDIR').strip()
+libs += ' ' + sc.get_config_var('BLDLIBRARY')
+print(libs)"
+am_python_print_lib_loc="\
+from distutils import sysconfig as sc
+print(sc.get_config_var('LIBDIR'))"
 if test "x$PYTHON_LIBS" == x; then
-	PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}"
+	PYTHON_LIBS=`$PYTHON -c "$am_python_print_libs"`
 fi
 if test "x$PYTHON_LIB_LOC" == x; then
-	PYTHON_LIB_LOC="${py_prefix}/lib" 
+	PYTHON_LIB_LOC=`$PYTHON -c "$am_python_print_lib_loc"`
 fi
 AC_SUBST(PYTHON_LIBS)
 AC_SUBST(PYTHON_LIB_LOC)
diff --git a/plugins/python/glade-python.c b/plugins/python/glade-python.c
index 132dce8..d8b5407 100644
--- a/plugins/python/glade-python.c
+++ b/plugins/python/glade-python.c
@@ -26,6 +26,15 @@
 
 #include <gladeui/glade.h>
 
+#if PY_MAJOR_VERSION >= 3
+#define IS_PY3K
+#define PY_CHARTYPE wchar_t
+#else
+// include bytesobject.h to map PyBytes_* to PyString_*
+#include <bytesobject.h>
+#define PY_CHARTYPE char
+#endif
+
 static void
 python_init (void)
 {
@@ -36,7 +45,7 @@ python_init (void)
 
   Py_InitializeEx (0);
 
-  PySys_SetArgv (1, (char **) &argv);
+  PySys_SetArgv (1, (PY_CHARTYPE **) &argv);
 }
 
 static void
@@ -79,7 +88,7 @@ glade_python_setup ()
   gchar *command;
   const gchar *module_path;
 
-  Py_SetProgramName (PACKAGE_NAME);
+  Py_SetProgramName ((PY_CHARTYPE *) PACKAGE_NAME);
 
   /* Initialize the Python interpreter */
   python_init ();
@@ -98,7 +107,7 @@ glade_python_setup ()
                  "please make sure it is in python's path (sys.path). "
                  "(use PYTHONPATH env variable to specify non default paths)\n%s",
                  PYGOBJECT_REQUIRED_MAJOR, PYGOBJECT_REQUIRED_MINOR,
-                 PYGOBJECT_REQUIRED_MICRO, PyString_AsString (pvalue));
+                 PYGOBJECT_REQUIRED_MICRO, PyBytes_AsString (pvalue));
       PyErr_Clear ();
       Py_Finalize ();
 
