【问题标题】:Attribute Error with: "import umap.umap_ as UMAP"属性错误:\"import umap.umap_ as UMAP\"
【发布时间】:2022-08-17 02:43:25
【问题描述】:

使用 numba = 0.55.1 和 umap learn = 0.5.2 的 jupyter 实验室。 umap 有“pypi”作为通道而 numba 没有,这有关系吗?两者都在 anaconda3 中。我已经尝试了几种解决方案shown here.

因此,使用以下代码:

import umap.umap_ as UMAP

我收到以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\errors.py in new_error_context(fmt_, *args, **kwargs)

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower_block(self, block)
    234         \"\"\"
--> 235         Create CPython wrapper(s) around this function (or generator).
    236         \"\"\"

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower_inst(self, inst)
    379 
--> 380         elif isinstance(inst, ir.SetItem):
    381             signature = self.fndesc.calltypes[inst]

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower_assign(self, ty, inst)
    581 
--> 582         def cast_result(res):
    583             return self.context.cast(self.builder, res,

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in incref(self, typ, val)

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\runtime\\context.py in incref(self, builder, typ, value)
    217         \"\"\"
--> 218         self._call_incref_decref(builder, typ, value, \"NRT_incref\")
    219 

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\runtime\\context.py in _call_incref_decref(self, builder, typ, value, funcname)
    206             mod = builder.module
--> 207             fn = mod.get_or_insert_function(incref_decref_ty, name=funcname)
    208             # XXX \"nonnull\" causes a crash in test_dyn_array: can this

AttributeError: \'Module\' object has no attribute \'get_or_insert_function\'

During handling of the above exception, another exception occurred:

LoweringError                             Traceback (most recent call last)
~\\AppData\\Local\\Temp/ipykernel_12580/4057111716.py in <module>
----> 1 import umap.umap_ as UMAP

~\\anaconda3\\lib\\site-packages\\umap\\umap_.py in <module>
     30 import umap.distances as dist
     31 
---> 32 import umap.sparse as sparse
     33 
     34 from umap.utils import (

~\\anaconda3\\lib\\site-packages\\umap\\sparse.py in <module>
     10 import numpy as np
     11 
---> 12 from umap.utils import norm
     13 
     14 locale.setlocale(locale.LC_NUMERIC, \"C\")

~\\anaconda3\\lib\\site-packages\\umap\\utils.py in <module>
     39 
     40 @numba.njit(\"i4(i8[:])\")
---> 41 def tau_rand_int(state):
     42     \"\"\"A fast (pseudo)-random number generator.
     43 

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\decorators.py in wrapper(func)
    224 
    225     return wrapper
--> 226 
    227 
    228 def generated_jit(function=None, target=\'cpu\', cache=False,

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\dispatcher.py in compile(self, sig)
    977         else:
    978             return dict((sig, self.overloads[sig].metadata) for sig in self.signatures)
--> 979 
    980     def get_function_type(self):
    981         \"\"\"Return unique function type of dispatcher when possible, otherwise

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\dispatcher.py in compile(self, args, return_type)
    139 
    140     def _get_implementation(self, args, kws):
--> 141         impl = self.py_func(*args, **kws)
    142         # Check the generating function and implementation signatures are
    143         # compatible, otherwise compiling would fail later.

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\dispatcher.py in _compile_cached(self, args, return_type)
    153                     pyparam.kind != implparam.kind or
    154                     (implparam.default is not implparam.empty and
--> 155                      implparam.default != pyparam.default)):
    156                     ok = False
    157         if not ok:

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\dispatcher.py in _compile_core(self, args, return_type)
    166     \'_CompileStats\', (\'cache_path\', \'cache_hits\', \'cache_misses\'))
    167 
--> 168 
    169 class _CompilingCounter(object):
    170     \"\"\"

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler.py in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler.py in compile_extra(self, func)
    426     \"\"\"The default compiler
    427     \"\"\"
--> 428 
    429     def define_pipelines(self):
    430         # this maintains the objmode fallback behaviour

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler.py in _compile_bytecode(self)
    490         pm.add_pass(AnnotateTypes, \"annotate types\")
    491 
--> 492         # strip phis
    493         pm.add_pass(PreLowerStripPhis, \"remove phis nodes\")
    494 

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler.py in _compile_core(self)
    469         return pm
    470 
--> 471     @staticmethod
    472     def define_nopython_lowering_pipeline(state, name=\'nopython_lowering\'):
    473         pm = PassManager(name)

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler.py in _compile_core(self)
    460         pm.passes.extend(untyped_passes.passes)
    461 
--> 462         typed_passes = dpb.define_typed_pipeline(state)
    463         pm.passes.extend(typed_passes.passes)
    464 

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler_machinery.py in run(self, state)
    341     def dependency_analysis(self):
    342         \"\"\"
--> 343         Computes dependency analysis
    344         \"\"\"
    345         deps = dict()

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler_machinery.py in run(self, state)
    332                     raise BaseException(\"Legacy pass in use\")
    333             except _EarlyPipelineCompletion as e:
--> 334                 raise e
    335             except Exception as e:
    336                 msg = \"Failed in %s mode pipeline (step: %s)\" % \\

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler_lock.py in _acquire_compile_lock(*args, **kwargs)
     33         def _acquire_compile_lock(*args, **kwargs):
     34             with self:
---> 35                 return func(*args, **kwargs)
     36         return _acquire_compile_lock
     37 

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler_machinery.py in _runPass(self, index, pss, internal_state)
    287             mutated |= check(pss.run_initialization, internal_state)
    288         with SimpleTimer() as pass_time:
--> 289             mutated |= check(pss.run_pass, internal_state)
    290         with SimpleTimer() as finalize_time:
    291             mutated |= check(pss.run_finalizer, internal_state)

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\compiler_machinery.py in check(func, compiler_state)
    260 
    261         def check(func, compiler_state):
--> 262             mangled = func(compiler_state)
    263             if mangled not in (True, False):
    264                 msg = (\"CompilerPass implementations should return True/False. \"

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\typed_passes.py in run_pass(self, state)
    394                     else:
    395                         if isinstance(restype,
--> 396                                       (types.Optional, types.Generator)):
    397                             pass
    398                         else:

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower(self)
    136             self.lower_normal_function(self.fndesc)
    137         else:
--> 138             self.genlower = self.GeneratorLower(self)
    139             self.gentype = self.genlower.gentype
    140 

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower_normal_function(self, fndesc)
    190         entry_block_tail = self.lower_function_body()
    191 
--> 192         # Close tail of entry block
    193         self.builder.position_at_end(entry_block_tail)
    194         self.builder.branch(self.blkmap[self.firstblk])

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower_function_body(self)
    219 
    220     def lower_block(self, block):
--> 221         \"\"\"
    222         Lower the given block.
    223         \"\"\"

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\lowering.py in lower_block(self, block)
    233     def create_cpython_wrapper(self, release_gil=False):
    234         \"\"\"
--> 235         Create CPython wrapper(s) around this function (or generator).
    236         \"\"\"
    237         if self.genlower:

~\\anaconda3\\lib\\contextlib.py in __exit__(self, type, value, traceback)
    129                 value = type()
    130             try:
--> 131                 self.gen.throw(type, value, traceback)
    132             except StopIteration as exc:
    133                 # Suppress StopIteration *unless* it\'s the same exception that

~\\AppData\\Roaming\\Python\\Python38\\site-packages\\numba\\core\\errors.py in new_error_context(fmt_, *args, **kwargs)

LoweringError: Failed in nopython mode pipeline (step: native lowering)
\'Module\' object has no attribute \'get_or_insert_function\'

File \"..\\..\\..\\anaconda3\\lib\\site-packages\\umap\\utils.py\", line 53:
def tau_rand_int(state):
    <source elided>
    \"\"\"
    state[0] = (((state[0] & 4294967294) << 12) & 0xFFFFFFFF) ^ (
    ^

During: lowering \"state = arg(0, name=state)\" at C:\\Users\\User\\anaconda3\\lib\\site-packages\\umap\\utils.py (53)

    标签: python python-3.x error-handling


    【解决方案1】:

    你有没有找到解决办法?以这种方式导入 umap 时我也遇到错误

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2017-09-20
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2021-04-12
      • 1970-01-01
      相关资源
      最近更新 更多