#python #jupyter-notebook
#python #jupyter-записная книжка
Вопрос:
недавно я застрял при импорте модуля «timezonefinder», когда я запускаю этот код python в jupyter notebook:
import timezonefinder
Произошло следующее исключение:
NotImplementedError Traceback (most recent call last)
C:ProgramDataAnaconda3libsite-packagesnumbatargetsbase.py in get_constant_generic(self, builder, ty, val)
498 try:
--> 499 impl = self._get_constants.find((ty,))
500 return impl(self, builder, ty, val)
C:ProgramDataAnaconda3libsite-packagesnumbatargetsbase.py in find(self, sig)
49 if out is None:
---> 50 out = self._find(sig)
51 self._cache[sig] = out
C:ProgramDataAnaconda3libsite-packagesnumbatargetsbase.py in _find(self, sig)
58 else:
---> 59 raise NotImplementedError(self, sig)
60
NotImplementedError: (<numba.targets.base.OverloadSelector object at 0x0000020A10A2B0F0>, (readonly bytes(uint8, 1d, C),))
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
C:ProgramDataAnaconda3libsite-packagesnumbaerrors.py in new_error_context(fmt_, *args, **kwargs)
616 try:
--> 617 yield
618 except NumbaError as e:
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower_block(self, block)
258 loc=self.loc, errcls_=defaulterrcls):
--> 259 self.lower_inst(inst)
260
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower_inst(self, inst)
307 ty = self.typeof(inst.target.name)
--> 308 val = self.lower_assign(ty, inst)
309 self.storevar(val, inst.target.name)
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower_assign(self, ty, inst)
448 res = self.context.get_constant_generic(self.builder, ty,
--> 449 value.value)
450 self.incref(ty, res)
C:ProgramDataAnaconda3libsite-packagesnumbatargetsbase.py in get_constant_generic(self, builder, ty, val)
501 except NotImplementedError:
--> 502 raise NotImplementedError("Cannot lower constant of type '%s'" % (ty,))
503
NotImplementedError: Cannot lower constant of type 'readonly bytes(uint8, 1d, C)'
During handling of the above exception, another exception occurred:
LoweringError Traceback (most recent call last)
<ipython-input-19-34c219114d8a> in <module>()
----> 1 import timezonefinder
C:ProgramDataAnaconda3libsite-packagestimezonefinder__init__.py in <module>()
1 from __future__ import absolute_import, division, print_function, unicode_literals
2
----> 3 from .timezonefinder import TimezoneFinder
4
5 __version__ = '3.4.2'
C:ProgramDataAnaconda3libsite-packagestimezonefindertimezonefinder.py in <module>()
20 try:
21 import numba
---> 22 from .helpers_numba import coord2int, distance_to_polygon_exact, distance_to_polygon, inside_polygon,
23 all_the_same, rectify_coordinates, coord2shortcut, convert2coord_pairs, convert2coords
24 except ImportError:
C:ProgramDataAnaconda3libsite-packagestimezonefinderhelpers_numba.py in <module>()
307
308 # @cc.export('rectify_coordinates', dtype_2float_tuple(f8, f8))
--> 309 @njit(dtype_2float_tuple(f8, f8), cache=True)
310 def rectify_coordinates(lng, lat):
311 if lng > 180.0 or lng < -180.0 or lat > 90.0 or lat < -90.0:
C:ProgramDataAnaconda3libsite-packagesnumbadecorators.py in wrapper(func)
181 with typeinfer.register_dispatcher(disp):
182 for sig in sigs:
--> 183 disp.compile(sig)
184 disp.disable_compile()
185 return disp
C:ProgramDataAnaconda3libsite-packagesnumbacompiler_lock.py in _acquire_compile_lock(*args, **kwargs)
30 def _acquire_compile_lock(*args, **kwargs):
31 with self:
---> 32 return func(*args, **kwargs)
33 return _acquire_compile_lock
34
C:ProgramDataAnaconda3libsite-packagesnumbadispatcher.py in compile(self, sig)
653
654 self._cache_misses[sig] = 1
--> 655 cres = self._compiler.compile(args, return_type)
656 self.add_overload(cres)
657 self._cache.save_overload(sig, cres)
C:ProgramDataAnaconda3libsite-packagesnumbadispatcher.py in compile(self, args, return_type)
80 args=args, return_type=return_type,
81 flags=flags, locals=self.locals,
---> 82 pipeline_class=self.pipeline_class)
83 # Check typing error if object mode is used
84 if cres.typing_error is not None and not flags.enable_pyobject:
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
924 pipeline = pipeline_class(typingctx, targetctx, library,
925 args, return_type, flags, locals)
--> 926 return pipeline.compile_extra(func)
927
928
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in compile_extra(self, func)
372 self.lifted = ()
373 self.lifted_from = None
--> 374 return self._compile_bytecode()
375
376 def compile_ir(self, func_ir, lifted=(), lifted_from=None):
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in _compile_bytecode(self)
855 """
856 assert self.func_ir is None
--> 857 return self._compile_core()
858
859 def _compile_ir(self):
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in _compile_core(self)
842 self.define_pipelines(pm)
843 pm.finalize()
--> 844 res = pm.run(self.status)
845 if res is not None:
846 # Early pipeline completion
C:ProgramDataAnaconda3libsite-packagesnumbacompiler_lock.py in _acquire_compile_lock(*args, **kwargs)
30 def _acquire_compile_lock(*args, **kwargs):
31 with self:
---> 32 return func(*args, **kwargs)
33 return _acquire_compile_lock
34
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in run(self, status)
253 # No more fallback pipelines?
254 if is_final_pipeline:
--> 255 raise patched_exception
256 # Go to next fallback pipeline
257 else:
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in run(self, status)
244 try:
245 event(stage_name)
--> 246 stage()
247 except _EarlyPipelineCompletion as e:
248 return e.result
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in stage_nopython_backend(self)
715 """
716 lowerfn = self.backend_nopython_mode
--> 717 self._backend(lowerfn, objectmode=False)
718
719 def stage_compile_interp_mode(self):
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in _backend(self, lowerfn, objectmode)
664 self.library.enable_object_caching()
665
--> 666 lowered = lowerfn()
667 signature = typing.signature(self.return_type, *self.args)
668 self.cr = compile_result(
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in backend_nopython_mode(self)
651 self.calltypes,
652 self.flags,
--> 653 self.metadata)
654
655 def _backend(self, lowerfn, objectmode):
C:ProgramDataAnaconda3libsite-packagesnumbacompiler.py in native_lowering_stage(targetctx, library, interp, typemap, restype, calltypes, flags, metadata)
1046 lower = lowering.Lower(targetctx, library, fndesc, interp,
1047 metadata=metadata)
-> 1048 lower.lower()
1049 if not flags.no_cpython_wrapper:
1050 lower.create_cpython_wrapper(flags.release_gil)
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower(self)
176 if self.generator_info is None:
177 self.genlower = None
--> 178 self.lower_normal_function(self.fndesc)
179 else:
180 self.genlower = self.GeneratorLower(self)
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower_normal_function(self, fndesc)
217 # Init argument values
218 self.extract_function_arguments()
--> 219 entry_block_tail = self.lower_function_body()
220
221 # Close tail of entry block
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower_function_body(self)
242 bb = self.blkmap[offset]
243 self.builder.position_at_end(bb)
--> 244 self.lower_block(block)
245
246 self.post_lower()
C:ProgramDataAnaconda3libsite-packagesnumbalowering.py in lower_block(self, block)
257 with new_error_context('lowering "{inst}" at {loc}', inst=inst,
258 loc=self.loc, errcls_=defaulterrcls):
--> 259 self.lower_inst(inst)
260
261 def create_cpython_wrapper(self, release_gil=False):
C:ProgramDataAnaconda3libcontextlib.py in __exit__(self, type, value, traceback)
128 value = type()
129 try:
--> 130 self.gen.throw(type, value, traceback)
131 except StopIteration as exc:
132 # Suppress StopIteration *unless* it's the same exception that
C:ProgramDataAnaconda3libsite-packagesnumbaerrors.py in new_error_context(fmt_, *args, **kwargs)
623 from numba import config
624 tb = sys.exc_info()[2] if config.FULL_TRACEBACKS else None
--> 625 six.reraise(type(newerr), newerr, tb)
626
627
C:ProgramDataAnaconda3libsite-packagesnumbasix.py in reraise(tp, value, tb)
657 if value.__traceback__ is not tb:
658 raise value.with_traceback(tb)
--> 659 raise value
660
661 else:
LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
Cannot lower constant of type 'readonly bytes(uint8, 1d, C)'
File "C:ProgramDataAnaconda3libsite-packagestimezonefinderhelpers_numba.py", line 312:
def rectify_coordinates(lng, lat):
<source elided>
if lng > 180.0 or lng < -180.0 or lat > 90.0 or lat < -90.0:
raise ValueError(b'The coordinates should be given in degrees. They are out ouf bounds.')
^
[1] During: lowering "$const32.2 = const(bytes, b'The coordinates should be given in degrees. They are out ouf bounds.')" at C:ProgramDataAnaconda3libsite-packagestimezonefinderhelpers_numba.py (312)
Решения, которые я пробовал до сих пор:
- переустановите модуль «numba», не работает;
- удалите модуль «numba» напрямую, проблема решена, но скорость выполнения timezonefiner значительно снизилась;
Итак, кто-нибудь может знать, как решить эту проблему? Миллион благодарностей.
Ответ №1:
Вероятно, это потому, что timezonefinder не поддерживается numba. Вы можете проверить поддерживаемые функции python.
Информация о timezonefinder неясна, поэтому ссылка на поддерживаемые функции numba — это numba.
Взгляните на перегрузку с помощью numba для перегрузки (для использования «сторонней библиотеки, которой вы не управляете, и вы хотите предоставить Numba-совместимые реализации для определенных функций из этой библиотеки»)
Комментарии:
1. Но, похоже, «timezonefinder» может хорошо работать на ПК моих коллег.