NameError: name ‘_C’ is not defined while running python code in google colab

**when I run the following code in google colab **

` import matplotlib.pyplot as plt
    from PIL import Image
    import numpy as np
    import json
    import pandas
    import cv2
    import openslide
    from skimage import morphology
    import torch
    import torch.nn as nn

    import torch.nn.functional as F
    from torchvision import transforms
    import torch.optim as optim


    from sklearn.metrics import confusion_matrix
    from sklearn.metrics import accuracy_score
    from sklearn.metrics import classification_report

    import os
    import sys
    from tqdm import tqdm
    from efficientnet_pytorch import EfficientNet
    from google.colab import drive
    import seaborn as sn
    Image.MAX_IMAGE_PIXELS = 1000000000`

My task is related to openslide and pytorch. So when I run the code in google colab, I got the following error and how can I solve this

NameError                                 Traceback (most recent call last)
`<ipython-input-3-f44ae585884e> in <cell line: 9>()
      7 import openslide
      8 from skimage import morphology
----> 9 import torch
     10 import torch.nn as nn
     11 import torch.nn.functional as F

/usr/local/lib/python3.10/dist-packages/torch/__init__.py in <module>
    463     raise  # If __file__ is not None the cause is unknown, so just re-raise.
    464 
--> 465 for name in dir(_C):
    466     if name[0] != '_' and not name.endswith('Base'):
    467         __all__.append(name)`

NameError: name ‘_C’ is not defined

  • This question is also answered here. Please read How to ask and search on the internet if your question is already answered.

    – 




Leave a Comment