{ "metadata": { "name": "module-path-configurator" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": "Python Path Configurator\n====\n\nThis 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).\n\nInstructions\n----\nEdit 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.\n\nSee also\n----\nFor more information about modules, see that [section of the Python tutorial](http://docs.python.org/2/tutorial/modules.html).\n\nFor more information on what this notebook does, specifically, see documentation for the [`site`](http://docs.python.org/2/library/site.html) package in the Python Standard Library.\n" }, { "cell_type": "code", "collapsed": false, "input": "pathspec = r\"\"\"\n# Generated by path-configurator.ipynb\n# In the lines below, list the paths where Python should look for user-supplied modules,\n# one directory per line.\n#\n# If a directory does not exist when Python is started, it will be ignored.\n#\n# For more information, see the documentation for the \"site\" package.\nC:\\Users\\exampleuser\\example_module_dir\n\"\"\"", "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": "import site, os\nusp = site.getusersitepackages()\nif not os.path.exists(usp):\n os.makedirs(usp)\nuspfile = os.path.join(usp, 'userpaths.pth')\nopen(uspfile, 'w').write(pathspec)\nprint 'Wrote to ' + uspfile", "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": "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.*" }, { "cell_type": "code", "collapsed": false, "input": "import sys\nsys.path", "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }