在 Google Colabs 中安装 PyTorch

Installing PyTorch in Google Colabs

我目前正在尝试 运行 我在 Google Colabs 中的代码,为此我需要 PyTorch。这是我得到的反馈。

> ValueError                                Traceback (most recent call last)
<ipython-input-26-3d0da87b83cc> in <module>()
     13 #from sentence_transformers import SentenceTransformer
     14 get_ipython().system('pip install torch')
---> 15 import torch
     16 get_ipython().system('pip install transformers')
     17 from transformers import BertTokenizer, BertModel
> 
> /usr/local/lib/python3.7/dist-packages/torch/__init__.py in <module>()
>     195     if USE_GLOBAL_DEPS:
>     196         _load_global_deps()
> --> 197     from torch._C import *  # noqa: F403
>     198 
>     199 # Appease the type checker; ordinarily this binding is inserted by the
> 
> ValueError: module functions cannot set METH_CLASS or METH_STATIC

我读到它可能与 Numpy 有关并尝试了另一个版本,但也失败了。

删除旧的 numpy 和 运行 以下代码。

pip install -U numpy

找到解决方案 here