Skip to content

Accessing Python on Your Machine

Accessing Python on Your Machine

After you have Python installed on your system, you need to know where to find it. In some respects, Python does everything it can to make this process easy by performing certain tasks, such as adding the Python path to the machine’s path information during installation. Even so, you need to know how to access the installation, which the following sections describe.

 

 

Using Windows

A Windows installation creates a new folder in the Start menu that contains your Python installation. You can access it by choosing Start➪All Programs➪ Python 3.3. The two items of interest in the folder when creating new applica- tions are IDLE (Python GUI) and Python (command line).

 

 

 

 

 

Clicking IDLE (Python GUI) produces a graphical interactive environment like the one shown in Figure 2-6. When you open this environment, IDLE automatically displays some information so that you know you have the right application open. For example, you see the Python version number (which is 3.3.4 in this case). It also tells you what sort of system you’re using to run Python.

 

 

 

 

 

 

 

 

Figure 2-6:

Use IDLE

when you want the comforts of a graphical environment.

 

 

The Python (command line) option opens a command prompt and executes the Python command, as shown in Figure 2-7. Again, the environment auto- matically displays information such as the Python version and the host platform.

 

 

 

 

Figure  2-7: Use the command prompt when you want the speed and flexibility of a command­

line interface.

 

 

 

A third method to access Python is to open a command prompt, type Python, and press Enter. You can use this approach when you want to gain additional flexibility over the Python environment, automatically load items, or execute Python in a higher-privilege environment (in which you gain additional secu- rity rights). Python provides a significant array of command-line options that you can see by typing Python /? at the command prompt and pressing Enter. Figure 2-8 shows what you typically see. Don’t worry too much about these command-line options — you won’t need them for this book, but it’s helpful to know they exist.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 2-8: Using a standard command line offers the flexibility

of using switches to change the way Python

works.

 

 

To use this third method of executing Python, you must include Python  in the Windows path. This is why you want to choose the Add python.exe to Path option when installing Python on Windows. If you didn’t add the path during installation, you can add it afterward using the instructions found in the Adding a Location to the Windows Path article on my blog

 

 

at http://blog.johnmuellerbooks.com/2014/02/17/adding-a- location-to-the-windows-path/. This same technique works for adding Python-specific environment variables such as

 

  • PYTHONSTARTUP
  • PYTHONPATH
  • PYTHONHOME
  • PYTHONCASEOK
  • PYTHONIOENCODING
  • PYTHONFAULTHANDLER
  • PYTHONHASHSEED

 

None of these environment variables is used in the book. However, you can find out more about them at http://docs.python.org/3.3/using/ cmdline.html#environment-variables.

 

 

Using the Mac

When working with a Mac, you probably have Python already installed and don’t need to install it for this book. However, you still need to know where to find Python. The following sections tell you how to access Python depending on the kind of installation you performed.

 

Locating the default installation

The default OS X installation doesn’t include a Python-specific folder in most cases. Instead, you must open Terminal by choosing Applications➪Utilities➪ Terminal. After Terminal is open, you can type Python and press Enter to access the command-line version of Python. The display you see is similar to the one shown in Figure 2-7. As with Windows (see the “Using Windows” sec- tion of the chapter), using Terminal to open Python offers the advantage of using command-line switches to modify the manner in which Python works.

 

Locating the updated version of Python you installed

After you perform the installation on your Mac system, open the Applica- tions folder. Within this folder, you find a Python 3.3 folder that contains the following:

 

  • Extras folder
  • IDLE application (GUI development)
  • Python Launcher (interactive command development)
  • Update .. command

 

 

Double-clicking IDLE application opens a graphical interactive environment that looks similar to the environment shown in Figure 2-6. There are some  small cosmetic differences, but the content of the window is the same. Double- clicking Python Launcher opens a command-line environment similar to the one shown in Figure 2-7. This environment uses all the Python defaults to pro- vide a standard execution environment.

 

Even if you install a new version of Python on your Mac, you don’t have to settle for using the default environment. It’s still possible to open Terminal to gain access to the Python command-line switches. However, when you access Python from the Mac Terminal application, you need to ensure that you’re   not accessing the default installation. Make sure to add /usr/local/bin/ Python3.3 to your shell search path.

 

 

Using Linux

After the installation process is complete, you can find a Python 3.3 sub- folder in your home folder. The physical location of Python 3.3 on your Linux system is normally the /usr/local/bin/Python3.3 folder. This is impor- tant information because you may need to modify the path for your system manually. Linux developers need to type Python3.3, rather than just Python, when working at the Terminal window to obtain access to the Python 3.3.4 installation.