HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCriticalCanonical

Importing modules from parent folder

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
fromimportingparentfoldermodules

Problem

I am running Python 2.5.

This is my folder tree:

ptdraft/
  nib.py
  simulations/
    life/
      life.py


(I also have __init__.py in each folder, omitted here for readability)

How do I import the nib module from inside the life module? I am hoping it is possible to do without tinkering with sys.path.

Note: The main module being run is in the ptdraft folder.

Solution

It seems that the problem is not related to the module being in a parent directory or anything like that.

You need to add the directory that contains ptdraft to PYTHONPATH

You said that import nib worked with you, that probably means that you added ptdraft itself (not its parent) to PYTHONPATH.

Context

Stack Overflow Q#714063, score: 157

Revisions (0)

No revisions yet.