diff --git a/contrib/win32/hgwebdir_wsgi.py b/contrib/win32/hgwebdir_wsgi.py
--- a/contrib/win32/hgwebdir_wsgi.py
+++ b/contrib/win32/hgwebdir_wsgi.py
@@ -52,6 +52,7 @@ import sys
 # Enable tracing. Run 'python -m win32traceutil' to debug
 if getattr(sys, 'isapidllhandle', None) is not None:
     import win32traceutil
+    win32traceutil.SetupForPrint # silence unused import warning
 
 # To serve pages in local charset instead of UTF-8, remove the two lines below
 import os
@@ -90,6 +91,6 @@ def __ExtensionFactory__():
     return isapi_wsgi.ISAPISimpleHandler(handler)
 
 if __name__=='__main__':
-    from isapi.install import *
+    from isapi.install import ISAPIParameters, HandleCommandLine
     params = ISAPIParameters()
     HandleCommandLine(params)
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -33,12 +33,14 @@ try:
 except ImportError:
     try:
         import sha
+        sha.sha # silence unused import warning
     except ImportError:
         raise SystemExit(
             "Couldn't import standard hashlib (incomplete Python install).")
 
 try:
     import zlib
+    zlib.compressobj # silence unused import warning
 except ImportError:
     raise SystemExit(
         "Couldn't import standard zlib (incomplete Python install).")
@@ -56,6 +58,7 @@ if isironpython:
 else:
     try:
         import bz2
+        bz2.BZ2Compressor # silence unused import warning
     except ImportError:
         raise SystemExit(
             "Couldn't import standard bz2 (incomplete Python install).")
@@ -129,6 +132,7 @@ def hasfunction(cc, funcname):
 # py2exe needs to be installed to work
 try:
     import py2exe
+    py2exe.Distribution # silence unused import warning
     py2exeloaded = True
     # import py2exe's patched Distribution class
     from distutils.core import Distribution
diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -148,6 +148,7 @@ def has_cacheable_fs():
 def has_lsprof():
     try:
         import _lsprof
+        _lsprof.Profiler # silence unused import warning
         return True
     except ImportError:
         return False
@@ -164,6 +165,7 @@ def has_git():
 def has_docutils():
     try:
         from docutils.core import publish_cmdline
+        publish_cmdline # silence unused import
         return True
     except ImportError:
         return False
@@ -270,6 +272,7 @@ def has_pyflakes():
 def has_pygments():
     try:
         import pygments
+        pygments.highlight # silence unused import warning
         return True
     except ImportError:
         return False
@@ -288,6 +291,7 @@ def has_outer_repo():
 def has_ssl():
     try:
         import ssl
+        ssl.wrap_socket # silence unused import warning
         import OpenSSL
         OpenSSL.SSL.Context
         return True
diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
--- a/tests/test-check-pyflakes.t
+++ b/tests/test-check-pyflakes.t
@@ -7,16 +7,6 @@ run pyflakes on all tracked files ending
 
   $ hg locate 'set:**.py or grep("^!#.*python")' 2>/dev/null \
   > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
-  contrib/win32/hgwebdir_wsgi.py:*: 'win32traceutil' imported but unused (glob)
-  setup.py:*: 'sha' imported but unused (glob)
-  setup.py:*: 'zlib' imported but unused (glob)
-  setup.py:*: 'bz2' imported but unused (glob)
-  setup.py:*: 'py2exe' imported but unused (glob)
-  tests/hghave.py:*: '_lsprof' imported but unused (glob)
-  tests/hghave.py:*: 'publish_cmdline' imported but unused (glob)
-  tests/hghave.py:*: 'pygments' imported but unused (glob)
-  tests/hghave.py:*: 'ssl' imported but unused (glob)
-  contrib/win32/hgwebdir_wsgi.py:93: 'from isapi.install import *' used; unable to detect undefined names (glob)
   tests/filterpyflakes.py:58: undefined name 'undefinedname'