import sys, os
os.chdir("C:\Coding\DeepLearning")
sys.path.append(os.pardir)
import numpy as np
from dataset.mnist import load_mnist
from TwoLayerNet import TwoLayerNet
In this phrase, o.s.What does Pardir mean? Do you mean to paste the path of the directory where that file exists? That file is
C:\Coding\DeepLearning\Backforward
A file that exists in this path and the mnist module underneath it is
C:\Coding\DeepLearning\dataset
It exists in this path.
If you run it like that,
traceback. : (most recent call last)
File "C:\Coding\DeepLearning\Backforward\gradient_check.py", line 5, in <module>
from dataset.mnist import load_mnist
ModuleNotFoundError: No module named 'dataset'
[Finished in 0.522s]
It extracts these error codes.
python
os.pardir refers to the parent directory of the current directory.
Modify sys.path.append(os.pardir) to sys.path.append('C:\Coding\DeepLearning') and test it
The C:\Coding\DeepLearning\dataset directory must have _init__.py
.
Study more about Python's package items.
import sys
sys.path
You can see the set path by checking the value of .
You can add one of those paths and I want to add a separate pathCotton
You can add it at runtime with sys.path.append above.
If it's Windows, at the place where you register environmental variables
Variable Name: PYTHONPATH
Variable value: %PYTHONPATH%; desired path
You can set it up system-wide in the same format as .
© 2024 OneMinuteCode. All rights reserved.