Sean Francis N. Ballais Sean Francis N. Ballais - 1 year ago 87
Python Question

How to access a module from outside your file folder in Python?

How can I access modules from another folder?

Here's the file structure:

/test # I'm here

I wanted to access the functions from from . How would I do this?

Here is my import:

import config.config

When I run the
script, it will always say:

ImportError: No module named config.config

Did I do something wrong?

Answer Source

The simplest way is to modify the sys.path variable (it defines the import search path):

# Bring your packages onto the path
import sys, os
sys.path.append(os.path.abspath(os.path.join('..', 'config')))

# Now do your import
from config.config import *
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download