Tuesday, May 15, 2012

PySide in Eclipse

Here's a quick note about getting rid of PySide errors in Eclipse if you're getting them - I installed PySide and all the examples work just fine, but Eclipse is flagging everything PySide-related as an error. You have to do a couple things:
  • PySide might have been installed in a non-standard location:
    • In Spotlight, search for "PySide", probably limiting to the /Library directory
    • If you find the PySide folder, click it to see where it got installed - in my case, it was installed at /Library/Python/2.7/site-packages/PySide, even though the /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 could import PySide without any trouble
    • If this is the case with you, go to Eclipse -> Preferences -> PyDev -> Interpreter - Python -> Libraries
    •  Click "New Folder"
    • Navigate to the site-packages directory that contains PySide (not the PySide directory itself!)
  • Like PyQt4, PySide wraps .so ("shared object") files, not actual python, so you'll also need to:
    • In the same screen (Eclipse -> Preferences -> PyDev -> Interpreter - Python), click the "Forced Builtins" tab, click "New...", type "PySide", and click "OK"


  1. Hi,
    I follow all the instruction but still got this error.
    from PySide import QtGui
    ImportError:No module named PySide.

    Please help me to fix this problem.

    1. There are a couple of things that could be wrong... I assume your code runs correctly (this post is just about Eclipse flagging errors that aren't errors - if something's actually wrong with your code or your PySide or Python installation, this won't help you)?

      If you've installed a lot of libraries since setting up your PyDev environment, Eclipse doesn't keep track of those changes. The fastest way to update your setup is to just click "Auto Config" and see if there are new libraries you need to check. I've found that that sometimes misses a library or two, though, so you might just want to click "Remove", "New...", find your python installation, and try these steps again.

      If that's still not working, knowing about your setup might help... Are you on OS X, Windows, Linux? Which version of python are you using (for example, I was using the 32-bit Python 2.7 from python.org, not the one that came with OS X). Also, I'm assuming you used the PySide installer or a Linux package manager to install it?

    2. Hi Alex,
      I'm on Linux (Ubuntu 11.10). I use python 2.7.3 and PySide 1.1.1. The code runs correctly, I try to use Eclipse but when I try to import the source code and try to run. And I already got this error: from PySide import QtGui
      ImportError:No module named PySide.

    3. This are the things that I installed on my machine (Python2.7,setuptools,PySide,PyInstaller).

    4. Hmmm... I originally wrote this post for a OS X, so to test I just installed Eclipse (Juno) and PyDev in Linux (I'm using Mint, but it shouldn't be too different) with Python 2.7 and PySide (I installed PySide with Synaptic Package Manager). The Auto Config was able to find PySide on its own (without doing my complicated additional steps).

      I don't know if I can help you much more than that - you might want to try googling the problem specifically for Linux. The steps in this post were about some of the weird nuances with the Mac installation of PySide, so I don't think they're relevant to you.