Reading Python Module from different PATH -
i have directory layout this:
pytest\ __init__.py connect.py sql.py test.py
what want pytest directory in python environment path can import modules i.e. connect.py, sql.py or test.py anywhere outside directory or interactive shell.
this have in __init__.py
:
from .connect import * .sql import * .test import *
for think parent directory should in python path. question how should go it?
for setting python path inside python script, can use sys.path.append()
method, method takes directory string need add python path.
example -
import sys sys.path.append(dir)
where dir
directory want add path , after files within dir file can imported without issues.
to set python take python files different directory directly through terminal or other means, need set pythonpath
variable, , not path
variable (path
variable used system find executables, not used python find modules/python files) .
pythonpath - variable tells python interpreter locate module files imported program. should include python source library directory , directories containing python source code. pythonpath preset python installer.
Comments
Post a Comment