diff --git a/setup.py b/setup.py
index ba09db267cb68e54523e64f213d4f1eea50be9ac_c2V0dXAucHk=..f6987f65435688d62124e7e1cc93f4c9481f6ec5_c2V0dXAucHk= 100644
--- a/setup.py
+++ b/setup.py
@@ -294,5 +294,7 @@
     hgenv['LANGUAGE'] = 'C'
     hgcmd = ['hg']
     # Run a simple "hg log" command just to see if using hg from the user's
-    # path works and can successfully interact with this repository.
+    # path works and can successfully interact with this repository.  Windows
+    # gives precedence to hg.exe in the current directory, so fall back to the
+    # python invocation of local hg, where pythonXY.dll can always be found.
     check_cmd = ['log', '-r.', '-Ttest']
@@ -298,10 +300,11 @@
     check_cmd = ['log', '-r.', '-Ttest']
-    try:
-        retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
-    except EnvironmentError:
-        retcode = -1
-    if retcode == 0 and not filterhgerr(err):
-        return hgcommand(hgcmd, hgenv)
+    if os.name != 'nt':
+        try:
+            retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
+        except EnvironmentError:
+            retcode = -1
+        if retcode == 0 and not filterhgerr(err):
+            return hgcommand(hgcmd, hgenv)
 
     # Fall back to trying the local hg installation.
     hgenv = localhgenv()