diff --git a/kwant/_common.py b/kwant/_common.py
index 50afc250b596750e6d9bf2171c4d6cbce72afffc..b9ea7aec8bc6b0c3953c495e8fbe3d2b88e15bcf 100644
--- a/kwant/_common.py
+++ b/kwant/_common.py
@@ -22,8 +22,7 @@ def get_version_from_git():
         return
     if p.wait() != 0:
         return
-    # TODO: use os.path.samefile once we depend on Python >= 3.3.
-    if os.path.normpath(p.communicate()[0].rstrip('\n')) != distr_root:
+    if not os.path.samefile(p.communicate()[0].decode().rstrip('\n'), distr_root):
         # The top-level directory of the current Git repository is not the same
         # as the root directory of the Kwant distribution: do not extract the
         # version from Git.
diff --git a/setup.py b/setup.py
index 3b884b97e239eedb01950de25217d13d3deb39f4..444fa71d82409d7b94ec85227f00ae09c5d118b2 100755
--- a/setup.py
+++ b/setup.py
@@ -16,7 +16,7 @@ import os
 import glob
 import imp
 import subprocess
-import ConfigParser
+import configparser
 from setuptools import setup, find_packages, Extension, Command
 from sysconfig import get_platform
 from distutils.errors import DistutilsError, DistutilsModuleError, \
@@ -263,7 +263,7 @@ def search_mumps():
     except OSError:
         pass
     else:
-        p.communicate(input='int main() {}\n')
+        p.communicate(input=b'int main() {}\n')
         if p.wait() == 0:
             return {'libraries': libs}
     return {}
@@ -297,7 +297,7 @@ def extensions():
                       'kwant/graph/c_slicer/slicer.h']})]
 
     #### Add components of Kwant with external compile-time dependencies.
-    config = ConfigParser.ConfigParser()
+    config = configparser.ConfigParser()
     try:
         with open(CONFIG_FILE) as f:
             config.readfp(f)
@@ -334,7 +334,7 @@ def extensions():
         if kwrds:
             build_summary.append('Auto-configured MUMPS')
     if kwrds:
-        for name, value in lapack.iteritems():
+        for name, value in lapack.items():
             kwrds.setdefault(name, []).extend(value)
         kwrds.setdefault('depends', []).extend(
             [CONFIG_FILE, 'kwant/linalg/cmumps.pxd'])