Forums

Import error for Orange

Hi! I`m trying to add a little bit of machine learning to my app and working with Orange to do this. I have app on Flask, Python 2.7 and try to import Orange 2.7.8 (which is preinstalled on pythonanywhere), but get an error after

import Orange

2015-03-18 09:41:33,559 :Traceback (most recent call last):
2015-03-18 09:41:33,559 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-03-18 09:41:33,560 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-03-18 09:41:33,560 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-03-18 09:41:33,560 :    self.error(msg, *args, **kwargs)
2015-03-18 09:41:33,560 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-03-18 09:41:33,560 :    self._log(ERROR, msg, args, **kwargs)
2015-03-18 09:41:33,560 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-03-18 09:41:33,561 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-03-18 09:41:33,561 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-03-18 09:41:33,561 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-03-18 09:41:33,561 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-03-18 09:41:33,561 :    self.threadName = threading.current_thread().name
2015-03-18 09:41:33,561 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-03-18 09:41:33,562 :    return _active[_get_ident()]
2015-03-18 09:41:33,562 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-03-18 09:41:33,562 :    app_iterator = self.app(environ, start_response)
2015-03-18 09:41:33,562 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-03-18 09:41:33,562 :    raise e
2015-03-18 09:41:33,562 :ValueError: Attempted relative import in non-package

Has no problem with Orange on my local machine and no problem with importing another libs. Could someone throw some light on this situation?

Hi there,

Are you sure this error is related to importing Orange? (eg: what happens if you take out the import Orange line- do you still get the same error?)

Yes, if i take out this import line - everything works fine.

If I do "import Orange" from a Python console, it works fine

And when I put it in a script it seems to work too.

Hmm. I just did a quick check by setting up a new standard flask app, and importing Orange, and I also do not get this error.

As an experiment, what error do you get if you run python /var/www/corplings_pythonanywhere_com_wsgi.py directly?

I get this:

Traceback (most recent call last):
  File "/var/www/corplings_pythonanywhere_com_wsgi.py", line 18, in <module>
    from main import app as application
  File "/home/corplings/mysite/main.py", line 9, in <module>
    app.config.from_object('config')
  File "/usr/local/lib/python2.7/dist-packages/flask/config.py", line 162, in from_object
    obj = import_string(obj)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 411, in import_string
    return __import__(import_name)
  File "/usr/local/lib/python2.7/dist-packages/Orange/OrangeCanvas/config.py", line 20, in <module>
    from .utils.settings import Settings, config_slot
ValueError: Attempted relative import in non-package

ah ok. I think this is because there is a config.py in Orange, and a config.py in flask, and they are conflicting with each other. This conflict is not apparent across different machines (eg: if your local machine has its PATH set so that it looks at the config.py from flask first instead of from Orange first)

I would try doing your Orange import later, or in a separate file. (eg: import data_mining_code, and within data_mining_code.py you import Orange)

Thanks a lot! It works now, after I imported Orange later as you said.