For those that have already read the rest of this page, here are some quick links to get you started each day in the lab. Download these two files to the desktop and run the batch script that Marcus has provided for us.
Some of the modules we will use in this class are part of Python’s standard library. Others must be downloaded and installed before we can use them.
This is the case with dnspython. You might be able to find a Windows installer for many Python packages. In some cases, this may be the best or only option. In other cases, we can use Python to download and install the package for us. This is usually the best approach because this approach is easy, it makes certain we have the right package for our Python installation, and the packages can be easily upgraded.
Python also contains it’s own facilities for installing new packages into an existing Python installation. They can query online databases and automatically download and install programs.
The Python package we will use to install other Python packages is called setuptools. Some Python packages are only distributed with Python egg files. An egg file is a platform independent means to distribute a Python package. It is much easier for the developers to make one egg package file than to build a Windows installer, a Dedian ‘.deb’ file, a Red Hat ‘.rpm’ file, a Solaris package, etc ...
Here, we will demonstrate how to install setuptools and use it to install other Python packages.
In addition to having Python installed, it is also necessary to update the %PATH% environment variable before proceeding to include Python’s bin and Scripts directories. (For Linux, only Python’s bin directory need be in the PATH variable.) If you installed Python in the default location (C:\Python27), then C:\Python27 and C:\Python27\Scripts needs to be added to the path. Environment variables are set in Window’s System Properties dialog box. Open Control Panel ‣ System (or right-click on My Computer and choose “Properties”). In the box that opens, click the “Advanced” tab to obtain the dialog box. Next, click the button labeled “Environment Variables”. It lists two kinds of variables – those that apply only to the current user and those that apply to the whole system. In the lower list of variables, select Path and then click on edit to add to the Path. Note that the items in the path are separated by semicolons (‘;’).
While you are editing environment variables, you might want to also edit %PATHEXT% adding .py to it’s list. This will allow you to enter just the name of a Python script (even leaving off the ‘.py’ extension) in the DOS Command prompt shell. Assuming .py files are associated with Python, which is usually accomplished when Python is installed, Python will automatically be used to run the script.
We want to install a package called distribute, which is used by the program that we will use when we install other Python packages. The easiest way to install distribute is to let Python do it for us. First download the setup program from: distribute_setup.py . Next, run the setup program:
Distribute (and Setuptools) can actually do a lot of different things associated with the distribution of Python packages. Next, we need to install a program called pip, which is a replacement for older program called easy_install. This tool works with a database from python.org now called PyPI for the Python Package Index. (It is sometimes called The Cheese Shop, which is a reference to a very funny Monty Python skit.) Any package which is registered on PyPI can be found, downloaded, installed and even updated with a simple invocation of pip.
Installation and usage of pip is documented on the pip project web page.