Note that for modules put on the directories listed in PYTHONPATH, Python won't search recursively down into the directory tree for things to import. The dialog box method of setting environment variables seems to work more reliably on some systems than the command-line method.
PYTHON MODULE ADD TO PATH OSX HOW TO
Instructions for how to set PYTHONPATH in Windows are given here (see Section 3.3.1). Microsoft Windows also has environment variables. If you are doing your work on a server set up for a class, your instructor should have set things up so you get the desired shell automatically when you log in. Note that you only have to issue the chsh command once to change your default shell you don't have to do it every time you log in. Be warned, though, that if you do this after you have installed Python, then the default python command may not point to the Python you installed, because the installer may not have set up a configuration file for the new shell you are using. On a Linux system you do the same, except you don't need the -s flag.
PYTHON MODULE ADD TO PATH OSX MAC OSX
If you prefer to run csh, on Mac OSX you can change your default shell by typing:
Which will also be used by tcsh if the file.
You can tell if your shell is csh or some flavor of it because the command line prompt ends with a % sign. In this shell, and its relative tcsh, to set PYTHONPATH you would type The other commonly used shell is csh (pronounced "c-shell" - get the joke?). (Files that begin with a period are invisible in the Finder, so it can be a bit tricky to open them in some text editors) Note the period at the beginning of the file name. You can put as many commands in this file as you want they will all be executed each time you create a new terminal window. profile (the startup file used by sh) if this file isn't found. For bash, the name of the configuration file isīut bash will use. However, it's a bit of a nuisance to rember to do this every time to want to work with Python, so the more usual thing is to create a configuration file in your home directory, using any text editor, and put the above command into that file. In sh and bash, you set the environment variable using the command You can also determine the default shell by typing the command You can also tell if you are running bash (or its relative sh) because the command-line prompt ends with a $. The name of the shell you are running appears at the top of the terminal window you open with the Terminal utility. A slight complication is that Unix-like operating systems (including Linux and Mac OSX) offer various different flavors of the command-line processor, called "shells," and the way you set environment variables depends on which shell you are using. (To list multiple directories to be searched, just separate them by a colon, e.g. Then, you want to set PYTHONPATH to this directory. Lets suppose that your home directory is /Users/frodo, and you have decided to put all your commonly used modules in /Users/frodo/MyModules. In any event, it may be helpful to some users to know what is really going on under the hood.
My setpath.py utility, in Courseware attempts to relieve users of the burden of dealing with shells and paths in detail. If you are running on a server, your instructor will have relieved you of the burden of knowing this stuff. Get ready for some truly geeky stuff below, but most users will not need to know about shells in this amount of detail. On Linux and Mac OSX systems, the business of telling Python where to look for modules is handled by setting the PYTHONPATH environment variable, which lists the directories Python should look in (besides the default ones) when a script imports a module.