diff --git a/mercurial/cext/pathencode.c b/mercurial/cext/pathencode.c
--- a/mercurial/cext/pathencode.c
+++ b/mercurial/cext/pathencode.c
@@ -660,7 +660,7 @@
 		if (name == NULL)
 			return -1;
 
-		hashlib = PyImport_Import(name);
+		hashlib = PyImport_ImportModule("hashlib");
 		Py_DECREF(name);
 
 		if (hashlib == NULL) {