2

I want to use numba package in QGIS. I installed numba in qgis then I want to test a simple code with numba. I used below code from http://numba.pydata.org/

from numba import jit
from numpy import arange

# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit
def sum2d(arr):
    M, N = arr.shape
    result = 0.0
    for i in range(M):
        for j in range(N):
            result += arr[i,j]
    return result

a = arange(9).reshape(3,3)
print(sum2d(a))

The result of this code is 36.0. But in QGIS I received this errors:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/tmp/tmp890NMS.py", line 16, in <module>
    print(sum2d(a))
  File "/usr/local/lib/python2.7/dist-packages/numba/dispatcher.py", line 307, in _compile_for_args
    return self.compile(tuple(argtypes))
  File "/usr/local/lib/python2.7/dist-packages/numba/dispatcher.py", line 579, in compile
    cres = self._compiler.compile(args, return_type)
  File "/usr/local/lib/python2.7/dist-packages/numba/dispatcher.py", line 80, in compile
    flags=flags, locals=self.locals)
  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 763, in compile_extra
    return pipeline.compile_extra(func)
  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 360, in compile_extra
    return self._compile_bytecode()
  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 722, in _compile_bytecode
    return self._compile_core()
  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 709, in _compile_core
    res = pm.run(self.status)
  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 246, in run
    raise patched_exception
KeyError: 'Caused By:\nTraceback (most recent call last):\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 238, in run\n    stage()\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 431, in stage_objectmode_frontend\n    cres = self.frontend_looplift()\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 421, in frontend_looplift\n    lifted=tuple(loops), lifted_from=None)\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 777, in compile_ir\n    lifted_from=lifted_from)\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 368, in compile_ir\n    return self._compile_ir()\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 729, in _compile_ir\n    return self._compile_core()\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 709, in _compile_core\n    res = pm.run(self.status)\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 246, in run\n    raise patched_exception\nKeyError: \'Caused By:\\nTraceback (most recent call last):\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 238, in run\\n    stage()\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 622, in stage_objectmode_backend\\n    self._backend(lowerfn, objectmode=True)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 599, in _backend\\n    lowered = lowerfn()\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 573, in backend_object_mode\\n    self.flags)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 905, in py_lowering_stage\\n    lower = objmode.PyLower(targetctx, library, fndesc, interp)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/lowering.py", line 65, in __init__\\n    self.env = Environment.from_fndesc(self.fndesc)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/lowering.py", line 21, in from_fndesc\\n    mod = fndesc.lookup_module()\\n  File "/usr/local/lib/python2.7/dist-packages/numba/funcdesc.py", line 77, in lookup_module\\n    return sys.modules[self.modname]\\nKeyError: \\\'__console__\\\'\\n\\nFailed at object (object mode backend)\\n\\\'__console__\\\'\'\n\nFailed at object (object mode frontend)\n\'Caused By:\\nTraceback (most recent call last):\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 238, in run\\n    stage()\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 622, in stage_objectmode_backend\\n    self._backend(lowerfn, objectmode=True)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 599, in _backend\\n    lowered = lowerfn()\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 573, in backend_object_mode\\n    self.flags)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/compiler.py", line 905, in py_lowering_stage\\n    lower = objmode.PyLower(targetctx, library, fndesc, interp)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/lowering.py", line 65, in __init__\\n    self.env = Environment.from_fndesc(self.fndesc)\\n  File "/usr/local/lib/python2.7/dist-packages/numba/lowering.py", line 21, in from_fndesc\\n    mod = fndesc.lookup_module()\\n  File "/usr/local/lib/python2.7/dist-packages/numba/funcdesc.py", line 77, in lookup_module\\n    return sys.modules[self.modname]\\nKeyError: \\\'__console__\\\'\\n\\nFailed at object (object mode backend)\\n\\\'__console__\\\'\'' 

With this error,Can I use numba in QGIS or not?

6
  • How did you install numba exactly? You say you "installed numba package in QGIS", but since its a python library you have to install it for a python. Does it work in python outside QGIS?
    – Spacedman
    Sep 15, 2017 at 7:46
  • Hi @Spacedman, I installed numba with pycharm in mint 18.2. In pycharm, above code run completely.Then in QGIS python console when I typed 'import numba' It worked whitout error and called numba.
    – HMadadi
    Sep 15, 2017 at 10:03
  • I wonder if there's a known problem running numba from an embedded Python....
    – Spacedman
    Sep 15, 2017 at 10:30
  • @Spacedman, Could this be about the LLVM compiler?
    – HMadadi
    Sep 15, 2017 at 10:37
  • Possibly... Does numba work from the command line python (ie not within pycharm) and how about ipython? Are they all the same pythons? Raise it on the numba github issues page, they may have some insight.
    – Spacedman
    Sep 15, 2017 at 10:39

0

Browse other questions tagged or ask your own question.