Package search paths

Typically, Python searches for modules in some specific system paths. You can print these paths by importing the sys module and printing the sys.path. This will actually return the strings inside the PYTHONPATH environment variable and inside the operating system; notice the result is just a normal Python list. You can add more paths to the search scope using a list function such as insert().

However, it's better to install the packages in the default search paths so the code won't break when you share it with other developers:

A simple package structure with a single module will be something like this:

The __init__ ...

Get Hands-On Enterprise Automation 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.