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.

alexandresaiz
  • 2,678
  • 7
  • 29
  • 40
  • possible duplicate of [Adding folder to Python's path permanently](http://stackoverflow.com/questions/3722248/adding-folder-to-pythons-path-permanently) – NightShadeQueen Jul 31 '15 at 01: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? – hyungwon yang Aug 03 '15 at 08:44

1 Answers1

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.

Slass33
  • 66
  • 9
  • 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. – hyungwon yang Aug 03 '15 at 08:48
  • [This might help](http://stackoverflow.com/questions/2860153/how-do-i-get-the-parent-directory-in-python). But if it doesn't then [check this](http://stackoverflow.com/questions/3430372/how-to-get-full-path-of-current-files-directory-in-python).If you haven't had enough links, [check this out](https://docs.python.org/3.1/library/site.html#module-site). **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**. – Slass33 Aug 03 '15 at 11:42