Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (1.6k points)

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.

2 Answers

0 votes
by (25.1k points)

You need to add the directory that contains ptdraft to PYTHONPATH. You can do this by adding the location to ptdraft at the end of PYTHONPATH environment variable in you pc's properties.

0 votes
by (106k points)

You can use relative imports for the Python versions greater than 2.5:

from ... import nib

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...