Now that we have reviewed the command line on Windows, we need to know a few other things before we start writing code. Let's start with where Python and any libraries are installed on your machine. Open Windows Explorer and navigate to C:Python27
, as shown in the following screenshot:
Inside the Python27
directory, you can see the python.exe
file; this is the application that our Path in System variables looks for to run Python scripts and commands. This folder also contains other libraries that are to required be run by Python, including libraries downloaded from easy_install or pip.
You can find the third-party libraries by navigating to C:Python27Libsite-packages
. Any libraries and any third-party dependencies downloaded through pip or easy_install will be installed in this directory by default.
Next, let's pull down a few libraries we will need for this book. Python 2.7 on Windows pip and easy_install are included with Python's Windows Installer by default. First, we will need the lxml
library. Now, on Windows, the lxml
library is a very popular C-based XML parser and writer library for Python libraries and is notoriously incompatible with Windows systems due to its C-based implementation. Let's install the lxml
library before pulling packages that might depend on this, staring with lxml
, as shown in the following screenshot:
lxml does come in both pip and easy_install flavors; however, since it's C-based, we require the Windows installer found at https://pypi.python.org/pypi/lxml/3.3.3. Grab the lxml-3.3.3.win32-py2.7.exe
file or a newer Version 2.7 library and run the installer. Once it's installed, we can confirm the installation by navigating to the site-packages
directory and checking whether any new folder called lxml
has been created. When installed, the site-packages
directory should look like the following screenshot:
After lxml
is installed, we will set up easy_install and pip. First, let's download easy_install and install it. The steps are as follows:
ez_setup.py
file.C:Python27ez_setup.py
. You can find the file on the page here, as shown in the following screenshot:Now, open your command prompt again with administrator privileges, then type the following command, and press Enter:
cd c:Python27
Next, type the following command and press Enter:
python ez_setup.py
When you're finished, your command prompt should look like the following screenshot:
Now, let's test easy_install and install pip at the same time! Again, open the command prompt and set your directory like you did previously:
cd c:Python27
Then, type the following command and press Enter:
easy_install pip
If you're successful, your command prompt should look something like the following screenshot:
With that done, let's test pip! We want to try to install a library called BeautifulSoup
. It's a common Python library for scrapping HTML content. We won't be using BeautifulSoup
but we need to test the pip installation, and BeautifulSoup
is a good library that works with most installations. To install BeautifulSoup
in your console while still it's open and the path is still pointing to your C:Python27
directory, type the following command:
pip install beautifulsoup
You'll see a message at the end, as shown in the following screenshot:
3.148.107.254