apex安装常见的三个报错并成功解决(亲测有效)

前三个方法我都遇到了错误,直到方法4才成功解决,建议看完全文后再决定使用哪种方法,或者直接使用方法4。

方法1

一开始我使用如下命令进行安装,

pip install apex

安装成功后,进入python,执行语句import apex进行验证是否安装成功,得到报错

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

方法2

于是在网上找了方法如下,遂将刚才安装的apex卸载,卸载命令为pip uninstall apex,然后根据如下的网上方法安装

git clone https://www.github.com/nvidia/apex
cd apex
python setup.py install

安装好后再次进行验证,得到报错如下

TypeError: unsupported operand type(s) for +: ‘NoneType‘ and ‘str‘

方法3

再次卸载,然后参考https://blog.csdn.net/qq_37844044/article/details/122625442,得到方法如下,相当于把方法2的第三行改为pip install -v –no-cache-dir ./

git clone https://github.com/NVIDIA/apex.git
cd apex
pip install -v --no-cache-dir ./

安装好后再次验证,得到报错

AttributeError: module 'torch.distributed' has no attribute '_all_gather_base'

方法4

再次卸载,然后参考这篇博文https://blog.csdn.net/weixin_44438120/article/details/112526744,方法如下

git clone https://github.com/ptrblck/apex.git
cd apex
git checkout apex_no_distributed
pip install -v --no-cache-dir ./

再次验证import apex成功(终于不报错了,搞了我两天呜呜呜)

注:遇到报错可以先翻github,比如在安装apex遇到报错时,可以进入https://github.com/NVIDIA/apex.git,点击issue,输入或粘贴报错查找是否有与自己有相同的问题的issue,看看别人是怎么解决的。最后祝大家好运!

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年7月6日
下一篇 2023年7月6日

相关推荐