Search code examples
pythoneclipsesimplecv

SimpleCV Code Completion with Eclipse


I recently managed to get SimpleCV up and running, after running into some issues. I now have a working SimpleCV installed and am using it with Eclipse Indigo. However, all my imports from SimpleCV are marked in red, and Eclipse states that it cannot find the specified import (even though the imported functions work fine).

Is there any way to have Eclipse recognize the imports from SimpleCV, so that I can make use of its Ctrl-Space code-complete functionality?

I tried to add "SimpleCV" to the Forced Builtins, but with no success. (This is what I did when I had the same problem for OpenCV, and it worked then)

Thanks for any advice!


Solution

  • Imports are very much broken in SimpleCV. I've been struggling with the same problem you're having. And the reason they don't want to fix it (as per their answers on their site (http://help.simplecv.org/question/472/code-completion-with-eclipse/) is not because they "all use vim, emacs, vi" but because a lot of their code relies on pulling alot of libraries into the local namespace with * imports. It's lazy programming at best, and really bad programming otherwise.

    Heck, you can't even import some of their files by themselves because they rely on the SimpleCV init.py file and base.py file being imported already. Both of those files have a lot of blanket imports. I was wondering why import SimpleCV took more than 2 seconds to run on my pc with an SSD. Now I know.

    Their init.py file has these imports:

    from SimpleCV.base import *
    from SimpleCV.Camera import *
    from SimpleCV.Color import *
    from SimpleCV.Display import *
    from SimpleCV.Features import *
    from SimpleCV.ImageClass import *
    from SimpleCV.Stream import *
    from SimpleCV.Font import *
    from SimpleCV.ColorModel import *
    from SimpleCV.DrawingLayer import *
    from SimpleCV.Segmentation import *
    from SimpleCV.MachineLearning import *
    

    And their base.py file has yet more imports:

    import os
    import sys
    import warnings
    import time
    import socket
    import re
    import urllib2
    import types
    import SocketServer
    import threading
    import tempfile
    import zipfile
    import pickle
    import glob #for directory scanning
    import abc #abstract base class
    import colorsys
    import logging
    import pygame as pg
    import scipy.ndimage as ndimage
    import scipy.stats.stats as sss  #for auto white balance
    import scipy.cluster.vq as scv    
    import scipy.linalg as nla  # for linear algebra / least squares
    import math # math... who does that 
    import copy # for deep copy
    import numpy as np
    import scipy.spatial.distance as spsd
    import scipy.cluster.vq as cluster #for kmeans
    import pygame as pg
    import platform
    import copy
    import types
    import time
    
    from numpy import linspace
    from scipy.interpolate import UnivariateSpline
    from warnings import warn
    from copy import copy
    from math import *
    from pkg_resources import load_entry_point
    from SimpleHTTPServer import SimpleHTTPRequestHandler
    from types import IntType, LongType, FloatType, InstanceType
    from cStringIO import StringIO
    from numpy import int32
    from numpy import uint8
    from EXIF import *
    from pygame import gfxdraw
    from pickle import *
    

    You know they claim to convert all these disparate CV libraries and apply "Pythonic" ways to them. But this import mess just plain out right proves them wrong.

    My attempt at fixing their imports was to remove all those import *'s from their init.py file which helps with the code completion lag that it presents in eclipse. Then importing the SimpleCV egg directory (C:\Python27\Lib\site-packages\simplecv-1.3-py2.7.egg) into eclipse as an external library. After that, I was able to run this:

    from SimpleCV.ImageClass import Image
    

    Same goes for importing Color:

    from SimpleCV.Color import Color
    

    There are cyclical imports, so beware of those as they might bite you. I myself had one earlier while trying to import SimpleCV.Color before importing SimpleCV.ImageClass. Note, with the above instructions, I seem to be able to get code-completion from Eclipse.