The sys.path.append() method

The sys.path function is a list (did you notice the square brackets in the preceding code output?) and as such can be appended or extended to include new file paths that will point to modules the user wants to import. To avoid the need to adjust sys.path, copy the module into the site-packages folder. When this is not possible, use the sys.path.append() method instead:

>>> sys.path.append("C:\\Projects\\Requests")
>>> sys.path
['', 'C:\\WINDOWS\\SYSTEM32\\python27.zip',
  'C:\\Python27\\ArcGIS10.2\\Dells',
  'C:\\Python27\\ArcGIS10.2\\lib',
..'C:\\Python27\\ArcGIS10.2\\lib\\plat-win',
..'C:\\Python27\\ArcGIS10.2\\lib\\lib-tk',
..'C:\\Python27\\ArcGIS10.2\\Lib\\site-packages\\pythonwin',
..'C:\\Python27\\ArcGIS10.2', ...

Get ArcPy and ArcGIS – Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.