Search code examples
pippytorchgoogle-colaboratory

Installing PyTorch in Google Colabs


I am currently trying to run my code in Google Colabs and for that I need PyTorch. This is the feedback I got.

> 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

I read that it could have to do with Numpy and tried another version, which also failed.


Solution

  • Remove the old numpy and run the following code.

    pip install -U numpy
    

    Found the solution here.