0

I have the same problem as expressed here (none of the solutions worked for me). I'll rephrase and tell you exactly where I am.

My folder structure is:

Mar29
     utils.py
     Subfolder
         running.py

Currently, I'm in the directory Mar29/Subfolder, and in the file running.py, I want to import all functions from utils.py.

Here's what I've tried at the top of running.py:

from .. import utils
from . import utils
from ../ import utils
import utils
from utils import *

The most common error I'm getting is:

ValueError: Attempted relative import in non-package

How can I import all functions from the utils.py file?

EDIT: also tried

from ..utils import *
from ../utils.py import *
from ../utils import *

Often got an invalid syntax error.

2
  • import utils ? Commented Mar 29, 2020 at 18:09
  • That's in my list of things tried. Commented Mar 29, 2020 at 18:11

1 Answer 1

0

The parent directory of the package is not being included in sys.path for security reasons. So add it to the path manually:

import sys
sys.path.insert(0,'..')

import utils
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.