Python Forum
ValueError: Attempted relative import in non-package
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: Attempted relative import in non-package
There are answers here: but I don't really understand them.

My directory structure is as follows:

Inside 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:

MacBook-Air:ff_nlp_trained_models Olly$ python Traceback (most recent call last): File "", line 14, in <module> from model_helpers import train_clf File "/Users/Olly/Documents/MSc/Natural Language Processing/Dissertation/dir1/", 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.

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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to import sklearn after installing any package ilango 0 804 Oct-25-2021, 07:03 AM
Last Post: ilango
  How to reference the relative directory when creating a photoimage kenwatts275 3 3,376 May-18-2021, 07:22 PM
Last Post: menator01
  Can't import package hubenhau 1 4,119 Jan-15-2021, 06:23 PM
Last Post: buran
  import scalalib package doesn't work manu_brighter 2 2,210 Apr-17-2020, 06:36 PM
Last Post: snippsat
  Importing module from a package results in import error goghvv 2 1,734 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Import all items from all modules from package DD169 3 1,464 Jan-25-2020, 12:33 PM
Last Post: buran
  pyautogui screenshotting region relative to image found on screen Bmart6969 3 5,187 Oct-05-2019, 06:20 PM
Last Post: Bmart6969
  how do i write a cross-platform relative file path? pseudo 2 2,264 Aug-23-2019, 05:07 PM
Last Post: ThomasL
  package import issues groovydingo 4 2,723 Oct-03-2018, 11:26 AM
Last Post: groovydingo
  function wanted: resolve relative path Skaperen 4 2,485 Sep-06-2018, 01:52 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020