Installing Third-Party Python Modules

Installing Third-Party Python Modules

Installing Third-Party Modules

Beyond the standard library of modules packaged with Python, other developers have written their own modules to extend Python’s capabilities even further. The primary way to install third-party modules is to use Python’s pip tool. This tool securely downloads and installs Python modules onto your computer from https://pypi.python.org/, the website of the Python Software Foundation. PyPI, or the Python Package Index, is a sort of free app store for Python modules.

The pip Tool

The executable file for the pip tool is called pip on Windows and pip3 on OS X and Linux. On Windows, you can find pip at C:\Python34\Scripts\pip.exe. On OS X, it is in /Library/Frameworks/Python.framework/Versions/3.4/bin/pip3. On Linux, it is in /usr/bin/pip3.

While pip comes automatically installed with Python 3.4 on Windows and OS X, you must install it separately on Linux. To install pip3 on Ubuntu or Debian Linux, open a new Terminal window and enter sudo apt-get install python3-pip. To install pip3 on Fedora Linux, enter sudo yum install python3-pip into a Terminal window. You will need to enter the administrator password for your computer in order to install this software.

Installing Third-Party Modules

The pip tool is meant to be run from the command line: You pass it the command install followed by the name of the module you want to install. For example, on Windows you would enter pip installModuleName, where ModuleName is the name of the module. On OS X and Linux, you’ll have to run pip3 with the sudo prefix to grant administrative privileges to install the module. You would need to type sudo pip3 installModuleName.

If you already have the module installed but would like to upgrade it to the latest version available on PyPI, run pip install –UModuleName (or pip3 install –UModuleName on OS X and Linux).

After installing the module, you can test that it installed successfully by running importModuleName in the interactive shell. If no error messages are displayed, you can assume the module was installed successfully.

You can install all of the modules covered in this book by running the commands listed next. (Remember to replace pip with pip3 if you’re on OS X or Linux.)

  • pip install send2trash

  • pip install requests

  • pip install beautifulsoup4

  • pip install selenium

  • pip install openpyxl==2.1.4

  • pip install PyPDF2

  • pip install python-docx (install python-docx, not docx)

  • pip install imapclient

  • pip install pyzmail

  • pip install twilio

  • pip install pillow

  • pip install pyobjc-core (on OS X only)

  • pip install pyobjc (on OS X only)

  • pip install python3-xlib (on Linux only)

  • pip install pyautogui

Note

For OS X users: The pyobjc module can take 20 minutes or longer to install, so don’t be alarmed if it takes a while. You should also install the pyobjc-core module first, which will reduce the overall installation time.

SOURCE: https://automatetheboringstuff.com/appendixa/

Comments are closed.