Python Forum

Full Version: ValueError: Attempted relative import in non-package
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There are answers here: https://stackoverflow.com/questions/1153...th-init-py but I don't really understand them.

My directory structure is as follows:

Output:
dir1/ __init__.py model_helpers.py quantity_pred_pickle.py quantity_pred.py tfidftransformer.py
Inside quantity_pred_pickle.py I have the following:

import quantity_pred
import tfidf_transformer
import model_helpers
quantity_pred and tfidf_transformer are imported without any problems, but when importing model_helpers I get the following error:

Output:
MacBook-Air:ff_nlp_trained_models Olly$ python quantity_pred_pickle.py Traceback (most recent call last): File "quantity_pred_pickle.py", line 14, in <module> from model_helpers import train_clf File "/Users/Olly/Documents/MSc/Natural Language Processing/Dissertation/dir1/model_helpers.py", line 14, in <module> from .tfidftransformer import TfIdfTransformer ValueError: Attempted relative import in non-package
How can I solve this? Why is it occurring? Thanks.

SOLVED
You can perhaps remove the dot in from .tfidftransformer import TfIdfTransformer