python - Importer des fichiers de différents dossiers

Mots clés : pythonimporterrorpython-importpython

meilleur 5 Réponses python - Importer des fichiers de différents dossiers

vote vote

96

# 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 
vote vote

88

from application.app.folder.file import func_name 
vote vote

73

application/app2/some_folder/some_file.py application/app2/another_folder/another_file.py 
import sys sys.path.append('../') 
vote vote

65

 import sys 
sys.path.insert(0, '/the/folder/path/name-package/') 
from name-package import name-module 
vote vote

55

# Linux & OSX export PYTHONPATH=$HOME/dirWithScripts/:$PYTHONPATH  # Windows set PYTHONPATH=C:\path\to\dirWithScripts\;%PYTHONPATH% 

Questions similaires