Path Problem : Nameerror: Name '__file__' Is Not Defined
import os.path as osp import torch import torch.nn as nn import torch.nn.functional as F from torch_geometric.datasets import MNISTSuperpixels import torch_geometric.transforms as
Solution 1:
In notebook, you need to use double quoted "__file__" as in osp.realpath("__file__")
instead of osp.realpath(__file__)
Sourced from: https://queirozf.com/entries/python-working-with-paths-the-filesystem#-nameerror-name-'file'-is-not-defined
Solution 2:
Per the documentation
__file__
is the pathname of the file from which the module was loaded, if it was loaded from a file. The__file__
attribute may be missing for certain types of modules, such as C modules that are statically linked into the interpreter; for extension modules loaded dynamically from a shared library, it is the pathname of the shared library file.
According the answer you can't get the path of a notebook pragrammatically. Use os.getcwd() as a workaround.
Post a Comment for "Path Problem : Nameerror: Name '__file__' Is Not Defined"