python - adding directory to sys.path /PYTHONPATH -


i trying import module particular directory.

the problem if use sys.path.append(mod_directory) append path , open python interpreter, directory mod_directory gets added end of list sys.path. if export pythonpath variable before opening python interpreter, directory gets added start of list. in latter case can import module in former, cannot.

can explain why happening , give me solution add mod_directory start, inside python script ?

this working documented. paths specified in pythonpath documented coming after working directory before standard interpreter-supplied paths. sys.path.append() appends existing path. see here , here. if want particular directory come first, insert @ head of sys.path:

import sys sys.path.insert(0,'/path/to/mod_directory') 

that said, there better ways manage imports either using pythonpath or manipulating sys.path directly. see, example, answers this question.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -