Recovering from ‘ImportError: No module named pysqlite2′ after upgrading python on a Gentoo Linux system


WARNING: Please read before continuing ▼

Difficulty: Moderate
Time: ~30 Minutes, depending on CPU speed/internet connection
Last Updated: 4th October 2009
Applies to: Gentoo Linux

Symptoms:

When running emerge after a major upgrade of pythons core files (dev-lang/python), you get an error similar to (other information may be included in the error message):

ImportError: No module named pysqlite2

emerge will fail to work as a result of this. Additionally, if you run /usr/sbin/python-updater, that will fail too, with a similar error.

Cause:

This issue is caused by a major version update of the python core files. Portage ordinarily has a mechanism to deal with this (/usr/sbin/python-updater), however it does not account for plugins.

Solution:

Firstly, make a backup copy of /etc/portage/modules (cp /etc/portage/modules /etc/portage/modules.old). After you have done this, open up /etc/portage/modules. In this file, there should be a line similar to:

portdbapi.auxdbmodule = cache.sqlite.database

Remove this line, and save changes to the file.

After you have done this, run:

/usr/sbin/python-updater

This command will now complete successfully. It will take some time to complete, depending on the speed of your computers processor.

Once this is done, restore the backup copy of /etc/portage/modules (mv /etc/portage/modules.old /etc/portage/modules) and delete the backup copy (rm -i /etc/portage/modules.old).

The final step is to regenerate the cache, as was done when you first configured portage to use sqlite as a cache.
Remove the old static cache:

rm -rf /var/cache/edb/dep

And regenerate the cache:

emerge –metadata

Portage should now be back to its old, fully functional self.

Sources and Further Reading:

Gentoo Wiki: Portage SQLite Cache

, , , , , ,

  1. No comments yet.
(will not be published)


Technical Procedures is Digg proof thanks to caching by WP Super Cache