TypeError:Python3中无法提供类建议请改用@implementer类装饰器

问题描述

我正在尝试使用以下方式安装Hugging Face的变形金刚

pip安装变压器

但这给了我这个错误。 我尝试安装NVIDIA的Apex,但在Mac上不起作用。

PS:我想在Mac上安装变形金刚(不支持GPU)

!pip install transformers

我还安装了NVIDIA的顶点。

错误

TypeError                                 Traceback (most recent call last)
<ipython-input-1-279c49635b32> in <module>
----> 1 import transformers

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transformers/__init__.py in <module>
     21 
     22 # Configurations
---> 23 from .configuration_albert import ALBERT_PRETRAINED_CONfig_ARCHIVE_MAP,AlbertConfig
     24 from .configuration_auto import ALL_PRETRAINED_CONfig_ARCHIVE_MAP,CONfig_MAPPING,AutoConfig
     25 from .configuration_bart import BartConfig

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transformers/configuration_albert.py in <module>
     16 """ ALBERT model configuration """
     17 
---> 18 from .configuration_utils import PretrainedConfig
     19 
     20 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transformers/configuration_utils.py in <module>
     23 from typing import Dict,Tuple
     24 
---> 25 from .file_utils import CONfig_NAME,cached_path,hf_bucket_url,is_remote_url
     26 
     27 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transformers/file_utils.py in <module>
    101 
    102 try:
--> 103     from apex import amp  # noqa: F401
    104 
    105     _has_apex = True

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apex/__init__.py in <module>
     16 from apex.exceptions import (ApexAuthSecret,17                              ApexSessionSecret)
---> 18 from apex.interfaces import (ApexImplementation,19                              IApex)
     20 from apex.lib.libapex import (groupfinder,/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apex/interfaces.py in <module>
      8     pass
      9 
---> 10 class ApexImplementation(object):
     11     """ Class so that we can tell if Apex is installed from other 
     12     applications

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apex/interfaces.py in ApexImplementation()
     12     applications
     13     """
---> 14     implements(IApex)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/zope/interface/declarations.py in implements(*interfaces)
    704     # the coverage for this block there. :(
    705     if python3:
--> 706         raise TypeError(_ADVICE_ERROR % 'implementer')
    707     _implements("implements",interfaces,classImplements)
    708 

TypeError: Class advice impossible in python3.  Use the @implementer class decorator instead.

解决方法

您已经安装了wrong apex project;这是针对Pyramid Web框架的项目,而PyPI上的最新版本与Python 3不兼容。

您需要卸载该项目,然后安装正确的项目NVIDIA Apex project。请注意,该项目具有different installation instructions,其中涉及创建git存储库的本地克隆,然后编译扩展代码。考虑到这需要C ++编译器和最新的CUDA版本。如果您拥有XCode command-line tools installed,则拥有所需的编译器,而NVIDIA提供installation instructions for CUDA

要卸载错误的项目,使用它(从您的笔记本电脑)应该就足够了:

pip uninstall apex

然后按照提示进行操作。如果您还没有这样做,则必须重新启动笔记本。您可以通过在新鲜 Python解释器或重新启动的笔记本中使用import apex来验证项目已消失。如果import apex仍然成功,请使用print(apex.__file__)找到安装位置,以便您可以手动删除apex目录和同一位置的任何apex-*.dist-info目录。

我确实注意到该项目似乎仅支持Linux,在较小程度上支持Windows,并且有一个open bug report on using it on macOS Mojave。我本人没有支持CUDA的Mac(MacBook Pro没有NVIDIA GPU),尽管我怀疑该错误报告不再适用(特定于有问题的组件已经since been moved to the contrib area并且进行了许多更新;自该错误报告以来,已经有over 500 commits to the project