diff --git a/autoscripts/preinst-pycentral-clean b/autoscripts/preinst-pycentral-clean
new file mode 100644
index 0000000000000000000000000000000000000000..a89a52180ea7e8f6753616eb4dac12c03e36613e
--- /dev/null
+++ b/autoscripts/preinst-pycentral-clean
@@ -0,0 +1,6 @@
+# make sure python-central files are removed before new package is installed
+if [ -f /var/lib/pycentral/#PACKAGE#.pkgremove ] || [ -f /var/lib/pycentral/pkgremove ]
+then
+	pycentral pkgremove #PACKAGE#
+	rm -f /var/lib/pycentral/#PACKAGE#.pkgremove
+fi
diff --git a/debian/changelog b/debian/changelog
index a05ce732a52a1c723e56d1a1372b0173d49f15ba..090f982c33dec9025624496ffa943ef5dee65030 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+python-defaults (2.6.5-6) UNRELEASED; urgency=low
+
+  * dh_python2:
+    - invoke `pycentral pkgremove foo` in preinst if upgrading from
+      python-central based package
+
+ -- Piotr Ożarowski <piotr@debian.org>  Sun, 27 Jun 2010 13:20:01 +0200
+
 python-defaults (2.6.5-5) unstable; urgency=medium
 
   * Use Python's compileall module instead of pycompile to byte-compile
diff --git a/dh_python2 b/dh_python2
index 94befa980dbe9956afb699fbea58bc3d84cf231e..310de4d9afc6767ca2e4bac83f97b0b828846282 100755
--- a/dh_python2
+++ b/dh_python2
@@ -564,6 +564,7 @@ def main():
 
         pyclean_added = False  # invoke pyclean only once in maintainer script
         if stats['compile']:
+            dh.autoscript(package, 'preinst', 'preinst-pycentral-clean', '')
             dh.autoscript(package, 'postinst', 'postinst-pycompile', '')
             dh.autoscript(package, 'prerm', 'prerm-pyclean', '')
             pyclean_added = True