This notebook is an easy way to control in which directories your Python installation looks for user-supplied modules. This is a relatively informal way to make code that you write (or get from other programmers) available in all your Python scripts and notebooks. It's not to be confused with more formal ways to install Python packages (such as from PyPI).
Edit the contents of the pathspec
variable assigned in the cell below, to reflect the list of directories where you plan to store modules. Then execute the cell below it to write the contents of pathspec
to an appropriate Python configuration file.
For more information about modules, see that section of the Python tutorial.
For more information on what this notebook does, specifically, see documentation for the site
package in the Python Standard Library.
pathspec = r"""
# Generated by path-configurator.ipynb
# In the lines below, list the paths where Python should look for user-supplied modules,
# one directory per line.
#
# If a directory does not exist when Python is started, it will be ignored.
#
# For more information, see the documentation for the "site" package.
C:\Users\exampleuser\example_module_dir
"""
import site, os
usp = site.getusersitepackages()
if not os.path.exists(usp):
os.makedirs(usp)
uspfile = os.path.join(usp, 'userpaths.pth')
open(uspfile, 'w').write(pathspec)
print 'Wrote to ' + uspfile
After you restart this notebook's kernel, you can use the following cell to check that your changes are in effect. Note that the directories you specified above must already exist in order to appear here.
import sys
sys.path