Installing Python modules
We have several techniques to install a Python module or package:
- We can write
setup.py
and use the distribution utilities module,distutils
, to install the package into Python'slib/site-packages
directory. See Distributing Python Modules. - We can set the
PYTHONPATH
environment variable to include our packages and modules. We can set this temporarily in a shell, or we can set it more permanently by editing our~/.bash_profile
or the system's/etc/profile
. We'll take a look at this in a little more depth in the later section. - We can include the
.pth
files to add directories to the import path. These files can be located in the local directory orlib/site-packages
to provide an indirect reference to a module or package. See ...
Get Mastering Object-oriented 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.