1

I was trying to add another module path. Let's say I want to append path 'd'

$ python3
>>> import sys
>>> sys.path
['a','b','c']

>>> sys.path.append('d')
>>> sys.path
['a','b','c','d']

>>> exit()
$python3
>>> import sys
>>> sys.path
['a','b','c']

The path I added is gone when I restart python. I would like to set the path 'd' as default.

2
  • possible duplicate of Adding folder to Python's path permanently Commented Jul 31, 2015 at 1:13
  • Thanks for your comment!!!! I found that PYTHONPATH solution before but I'm not sure that it will add paths into python3 path. Actually, I use python2.7 and python 3.4 but mostly I work on python3. So if I add paths by using PYTHONPATH then this command adds paths to python2 and python3 paths simultaneously? Commented Aug 3, 2015 at 8:44

1 Answer 1

0

The program restarts and sets to original settings, with only assigned values, that are in the program, when you open python again. I'd say you're best bet would be to add the

sys.path.append('d')
sys.path

lines of code into the main code.

There is another way, but it isn't 100% accurate and reliable. If you saved this program(you have to save the program) as, lets say, script.py, all you have to do is at the beginning of a new file type,

from script import *

(It helps if the file name isn't an actual module). This way may not work, and it has to have both files in the same folder, but it's the best way I know.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks!! It sounds much better than just typing every path. But it would be much nicer if I could access to the main path directory that holds default paths.
This might help. But if it doesn't then check this.If you haven't had enough links, check this out. PYTHONPATH is default search path for module files.The format is same shell’s PATH: directory pathnames separated. The default search path is installation dependent, usu. begins w/ prefix/lib/pythonversion, always added to PYTHONPATH.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.