julrog / nn_vis

A project for processing neural networks and rendering to gain insights on the architecture and parameters of a model through a decluttered representation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't import script from folder - No module named 'data'

yinqihuang opened this issue · comments

Code:
from data.mnist_data_handler import split_mnist_data

Error message:
C:\Users\Yinqi Huang\nn_vis>python examples/process_mnist_model.py Traceback (most recent call last): File "C:\Users\Yinqi Huang\nn_vis\examples\process_mnist_model.py", line 4, in <module> from data.mnist_data_handler import split_mnist_data ModuleNotFoundError: No module named 'data'

I have only tested it on windows with pycharm, where everything works fine (for me), but I think in your case maybe adding the __init__.py files in the directories will fix this. Either you try his, or wait until I will fix it after reproducing your error.

I know what is causing the issue. Until i fix it in a better way, for now you can simply add the following at the top of the .py file you want to run in the examples folder:

import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)

os.chdir('../')

from https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder

Fixed in commit 17403ab .