diff --git a/contrib/hgtk b/contrib/hgtk
--- a/contrib/hgtk
+++ b/contrib/hgtk
@@ -9,6 +9,16 @@
 
 import os
 import sys
+
+if "contrib" in sys.argv[0]:
+	tortoisehg_dir = os.path.abspath(sys.argv[0])
+	while True:
+		tortoisehg_dir, basename = os.path.split(tortoisehg_dir)
+		if basename == "contrib":
+			break
+	print "auto-detected tortoisehg_dir '%r'" % tortoisehg_dir
+	sys.path.append(tortoisehg_dir)
+	from hggtk import hglib
 
 dialogs = '''log synch status clone merge update userconfig repoconfig
 serve recovery commit datamine about'''

