This site is from a past semester! The current version will be here when the new semester starts.

Appendix A: Installing 3rd-Party Modules

In addition to built-in modules you get with Python by default, there are many modules written by others that you can make use of. You can install third-party modules using Python’s pip tool. This tool downloads and installs Python modules onto your computer from https://pypi.python.org/ (aka PyPi or Python Package Index).

First, ensure that you have pip installed by running this command in a command shell (not Python interpreter shell), which should print out the version of the pip tool you have.

pip --version

After that, to install a third-party module (or packages as they are sometimes called), you can run the pip install {packagename} command.

The example below shows how to install the colorama module that allows you to colorize text printed out to the console.

pip install colorama

Collecting colorama
  Downloading colorama-0.3.9-py2.py3-none-any.whl
Installing collected packages: colorama
Successfully installed colorama-0.3.9

After installing colorama, you can import it into your code and use its features to print colorized text.

import colorama

colorama.init()  # one-time initialization

print(colorama.Fore.YELLOW + ' Some yellow text')
print(colorama.Fore.BLUE + colorama.Back.WHITE + ' Some blue text in a white background')
print(colorama.Style.RESET_ALL + ' Back to normal now')


Some useful third-party modules:

  • colorama: For colorizing text printed in the console
  • selenium: For automating the Browser
  • pyzmail: For sending emails
  • twilio: For sending SMS
  • PyPDF2: For working with PDF files
  • pyperclip: To access the clipboard of the operating system
  • dateparser: To parse natural language repsentation of dates e.g., in 2 days, tomorrow

Resources:

Exercise: Print Errors in Red

Exercise : Print Errors In Red

Update a CLI program you have written in the past to print error messages in red color.

Colorama module does not work in Repl.it, or inside PyCharm. You'll need to run the program in a normal command shell to see the colors.