The import Search Path
We'll cover the following...
Before this goes any further, I want to briefly mention the library search path. Python looks in several places when you try to import a module. Specifically, it looks in all the directories defined in sys.path
. This is just a list, and you can easily view it or modify it with standard list methods. (You’ll learn more about lists in Native Datatypes.)
Press + to interact
import sys #①print (sys.path) #②#['/usercode',# '/usr/lib/python3.4',# '/usr/lib/python3.4/plat-x86_64-linux-gnu',# '/usr/lib/python3.4/lib-dynload',# '/usr/local/lib/python3.4/dist-packages',# '/usr/lib/python3/dist-packages']print (sys) #③#<module 'sys' (built-in)>print (sys.path.insert(0, '/home/mark/diveintopython3/examples')) #④#Noneprint (sys.path) #⑤#['/home/mark/diveintopython3/examples',#'/usercode',#'/usr/lib/python3.4',#'/usr/lib/python3.4/plat-x86_64-linux-gnu',#'/usr/lib/python3.4/lib-dynload',#'/usr/local/lib/python3.4/dist-packages',#'/usr/lib/python3/dist-packages']
① Importing the ...