Archive for July, 2014

ImportError: cannot import name QVariant

July 21st, 2014 -- Posted in Tech | No Comments »

I was installing a self-compiled instance of calibre (all-in one ebook solution) on one of my virtual machine when I ran into a particularly unhelpful python error: “ImportError: cannot import name QVariant”.

First of all, a little bit about my situation. I do my compiling on a separate development vm, which has a lot of packages installed. I run slackware 14.0 (custom install) – strictly 64 bit. I used a slackbuild to compile, so all dependencies were listed and I had compiled & installed them previously. This usually means that all dependency errors can be resolved with packages present in a slackpkg mirror.

Logically, the first place to look with a python error is python. So I fired it up and ran the offending command, hoping it would provide me with some more useful error message:

from PyQt4.Qt import QVariant

The original command was a bit longer, but this was the part the error was about. But no luck here, the error message was exactly the same. I tried “import PyQt4.Qt” after that, but no error there.

Seeing as I did not get any errors during compilation, I tried firing up calibre at my dev vm. No errors. So I decided to run the offending command in python there too (in verbose mode) and compare the results to the non-working machine.

No clear problem spotted, but I noticed that all files mentioned were in the same directory (/usr/lib64/python2.7/site-packages/PyQt4). Both machines had the exact same stock PyQt4 version, but who knows what went wrong during the installation, so i decided to take a look there.

There was nothing missing, or different, but I noticed this file: pyqtconfig.py

I thought, what the heck. Let’s run it. And yes, there was the actual error: ImportError: No module named sipconfig. A quick slackpkg search pointed me towards the sip package, and after that was installed, I ran the pyqtconfig.py file, and calibre started without problems!

Now you ask, why didn’t I say so right away? Well, because learning to solve errors by yourself is hard. It took me a long time, and I hope that by reading about my methods, you’ll get better at it too. Good luck!