Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Orange returns "ImportError: no module named orange"

I'd like to use the Orange package for scientific analysis . Installation on x86_64 Ubuntu 12.04, with Python 2.7.3, went well, using sudo easy_install orange. However, the package doesn't seem to be available for direct use:

11:30:43 leon@t410i:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import orange
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named orange
>>>

However, importing the package while running Python from the appropriate dist-packages subdirectory works fine:

11:34:02 leon@t410i:~$ cd /usr/local/lib/python2.7/dist-packages/Orange-2.5a4-py2.7-linux-x86_64.egg/Orange
11:34:32 leon@t410i:/usr/local/lib/python2.7/dist-packages/Orange-2.5a4-py2.7-linux-x86_64.egg/Orange$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import orange
>>> orange.__file__
'orange.so'
>>>

What is the problem? Other packages contained within dist-packages work fine when python's invoked from anywhere in the filesystem.

like image 658
Leon Derczynski Avatar asked Feb 19 '23 14:02

Leon Derczynski


1 Answers

The semantics for importing Orange have changed around version 2.5. If using code written with a previous version, some changes must be made, see http://orange.biolab.si/blog/2011/12/20/orange-25-code-conversion/. Critically, one needs to replace:

import orange

with:

import Orange

(note the capital letter O in the second example).

A side effect is that other sub-modules no longer need to be explicitly imported; a single

import Orange

is enough, instead of e.g.

import orange, orngTest, orngStat, orngTree
like image 173
Leon Derczynski Avatar answered Feb 22 '23 04:02

Leon Derczynski