首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AttributeError:模块“numpy.core.multiarray”没有属性“from_dlpack”

AttributeError:模块“numpy.core.multiarray”没有属性“from_dlpack”
EN

Stack Overflow用户
提问于 2022-07-26 11:05:18
回答 1查看 108关注 0票数 0

在导入依赖于numpy的库时,我得到了这个numpy.core.multiarray属性错误。

这可能与同时导入不同版本的NumPy有关。deepface,cv2与其他库一样在内部使用numpy数组。这些np版本可能相互冲突。如何解决这个问题?

我的进口产品是:

代码语言:javascript
运行
复制
import pandas as pd
import numpy as np

from deepface import (
    DeepFace,
    detectors as DeepFace_detectors
)

import cv2
from cv2 import (
    CascadeClassifier,
)
from mtcnn.mtcnn import MTCNN

from matplotlib import pyplot 
plt.rcParams["axes.grid"] = False
from matplotlib.pyplot import (
    imread,
    imshow
)
from matplotlib.patches import (
    Rectangle, 
    Circle
)
import glob
import os
import time
代码语言:javascript
运行
复制
AttributeError                            Traceback (most recent call last)
c:\Users\Documents\scripts\Predictive Analytics\Work\deepface\deepface.ipynb Cell 1 in <cell line: 1>()
----> 1 import pandas as pd
      2 import numpy as np
      4 from deepface import (
      5     DeepFace,
      6     detectors as DeepFace_detectors
      7 )

File c:\Users\anaconda3\envs\vision\lib\site-packages\pandas\__init__.py:11, in <module>
      9 for dependency in hard_dependencies:
     10     try:
---> 11         __import__(dependency)
     12     except ImportError as e:
     13         missing_dependencies.append(f"{dependency}: {e}")

File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\__init__.py:140, in <module>
    137 # Allow distributors to run custom init code
    138 from . import _distributor_init
--> 140 from . import core
    141 from .core import *
    142 from . import compat

File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\core\__init__.py:99, in <module>
     95 from .numeric import absolute as abs
     97 # do this after everything else, to minimize the chance of this misleadingly
     98 # appearing in an import-time traceback
---> 99 from . import _add_newdocs
    100 from . import _add_newdocs_scalars
    101 # add these for module-freeze analysis (like PyInstaller)

File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\core\_add_newdocs.py:1598, in <module>
   1447 add_newdoc('numpy.core.multiarray', 'fromfile',
   1448     """
   1449     fromfile(file, dtype=float, count=-1, sep='', offset=0, *, like=None)
   (...)
   1539         array_function_like_doc,
   1540     ))
   1542 add_newdoc('numpy.core.multiarray', 'frombuffer',
   1543     """
   1544     frombuffer(buffer, dtype=float, count=-1, offset=0, *, like=None)
   (...)
   1595         array_function_like_doc,
   1596     ))
-> 1598 add_newdoc('numpy.core.multiarray', 'from_dlpack',
   1599     """
   1600     from_dlpack(x, /)
   1601 
   1602     Create a NumPy array from an object implementing the ``__dlpack__``
   1603     protocol. Generally, the returned NumPy array is a read-only view
   1604     of the input object. See [1]_ and [2]_ for more details.
   1605 
   1606     Parameters
   1607     ----------
   1608     x : object
   1609         A Python object that implements the ``__dlpack__`` and
   1610         ``__dlpack_device__`` methods.
   1611 
   1612     Returns
   1613     -------
   1614     out : ndarray
   1615 
   1616     References
   1617     ----------
   1618     .. [1] Array API documentation,
   1619        https://data-apis.org/array-api/latest/design_topics/data_interchange.html#syntax-for-data-interchange-with-dlpack
   1620 
   1621     .. [2] Python specification for DLPack,
   1622        https://dmlc.github.io/dlpack/latest/python_spec.html
   1623 
   1624     Examples
   1625     --------
   1626     >>> import torch
   1627     >>> x = torch.arange(10)
   1628     >>> # create a view of the torch tensor "x" in NumPy
   1629     >>> y = np.from_dlpack(x)
   1630     """)
   1632 add_newdoc('numpy.core', 'fastCopyAndTranspose',
   1633     """_fastCopyAndTranspose(a)""")
   1635 add_newdoc('numpy.core.multiarray', 'correlate',
   1636     """cross_correlate(a,v, mode=0)""")

File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\core\function_base.py:521, in add_newdoc(place, obj, doc, warn_on_python)
    475 def add_newdoc(place, obj, doc, warn_on_python=True):
    476     """
    477     Add documentation to an existing object, typically one defined in C
    478 
   (...)
    519     If possible it should be avoided.
    520     """
--> 521     new = getattr(__import__(place, globals(), {}, [obj]), obj)
    522     if isinstance(doc, str):
    523         _add_docstring(new, doc.strip(), warn_on_python)

AttributeError: module 'numpy.core.multiarray' has no attribute 'from_dlpack'
EN

回答 1

Stack Overflow用户

发布于 2022-07-29 06:55:36

我重新建造了解决这个问题的conda env。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73122247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档