Importing Orange returns “ImportError: no module named orange”

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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.

回答1:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!