Import relative path python

Code examples

6
0

import python module from another directory

import sys
# sys.path is a list of absolute path strings
sys.path.append('/path/to/application/app/folder')

import file
3
0

import file from another directory python

# some_file.py
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')

import file
2
0

import local module python

# If the module is in the same directory:
import <module_name>

# If the module isn't in the same directory:
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')

import <module_name>
1
0

relative path python

import sys,os
sys.path.append(os.path.realpath('..'))
0
0

python how to import library absoluth path

import sys
sys.path.append('/foo/bar/my_module')
# Considering your module contains a function called my_func, you could import it:
from my_module import my_func
# Or you could import the module as a whole,
import my_module

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................