Many developers have written their own modules, extending Python’s capabilities beyond those provided by the standard library packaged with Python. The primary way to access third-party packages is to use Python’s pip tool, which securely downloads and installs modules onto your computer from the Python Package Index (PyPI) website, a sort of free app store for Python modules. This appendix provides instructions for installing the packages used throughout the book.
For general information about working with the command line, virtual environments, packages, and modules, see Chapter 12.
The executable file for the pip tool is named pip on Windows and pip3 on macOS and Linux. The pip tool has been included with Python since version 3.4. However, some distributions of Linux may not have it preinstalled.
To install pip3 on Ubuntu or Debian Linux, open a new terminal window and enter sudo apt install python3-pip. To install pip3 on Fedora Linux, enter sudo yum install python3-pip. These commands ask you to enter the administrator password for your computer.
If pip’s folder isn’t included in the PATH environment variable, you may have to change directories in the terminal window with the cd command before running pip. First, find your username by running echo %USERNAME% on Windows or whoami on macOS and Linux.
Then, on Windows, run the following command, specifying your username and adjusting the folder name for the version of Python you have installed:
C:\Users\al>cd C:\Users\your_username\AppData\Local\Programs\Python\Python313\Scripts
On macOS, run this command instead (making sure to specify the correct folder name):
al@Als-MacBook-Pro ~ %cd /Library/Frameworks/Python.framework/Versions/3.13/bin/
On Linux, run this command, specifying your username:
al@al-VirtualBox:~$ cd /home/your_username/.local/bin/
You should now be in the right folder to run the pip tool. Alternatively, you can add these folders to the PATH environment variable by following the instructions in “The PATH Environment Variable” on Chapter 12.
Some operating systems may not allow you to run pip without first creating and activating a virtual environment using Python’s built-in venv module. For learning Python and experimenting with code, it’s fine to create one virtual environment for all of your programs. See “Virtual Environments” on Chapter 12 for more details.
Because future changes to third-party packages may be incompatible with the book’s code examples, I recommend that you install the exact versions used in this book by adding ==version to the end of the module name. (Note the two equal signs in this command line option.) For example, pip install send2trash==1.8.3 installs version 1.8.3 of the send2trash package.
The easiest way to install all compatible packages at once is to install the automateboringstuff3 package. I’ll update this package as new versions of the third-party packages become available, so long as they’re compatible with the book’s code examples. If you’d like to install the newest versions, consult their online documentation for updated usage information.
On Windows, run the following command:
C:\Users\al>python –m pip install automateboringstuff3
On macOS and Linux, run this command:
al@Als-MacBook-Pro ~ % python3 –m pip install automateboringstuff3
To install Chapter 23’s PyAutoGUI package on Linux, you must take additional steps. Open a terminal window and run sudo apt install python3-tk and sudo apt install python3-dev. To get Chapter 8’s pyperclip module working on Linux, you must run sudo apt install xclip. You’ll need the computer’s administrator password.
As of publication, these commands install the following versions of packages:
beautifulsoup4 == 4.12.3
matplotlib==3.92
openpyxl==3.1.5
pdfminer.six==20240706
pillow==10.4.0
playsound3==2.4.0
playwright==1.47.0
PyPDF==5.0.1
python-docx==1.1.2
pyttsx3 == 2.98
requests==2.32.3
selenium==4.25.0
send2trash==1.8.3
xmltodict==0.13.0
In addition, the automateboringstuff3 package always installs the latest version of the these packages:
bext
ezgmail
ezsheets
humre
pyautogui
pymsgbox
pyperclip
pyperclipimg
yt-dlp
The Playwright package requires one more step to install separate browsers the module uses. After installing the automateboringstuff3 package, run playwright install to install the browsers that Playwright uses.
The pytesseract package covered in Chapter 22 and the openai-whisper package covered in Chapter 24 are fairly large, and some readers may not want to install them, so I’ve left them out of the automateboringstuff3 package. You can install them by running the following on Windows:
C:\Users\al>pip install pytesseract==0.3.10
C:\Users\al>pip install openai-whisper==20231117
On macOS and Linux, run the following:
al@Als-MacBook-Pro ~ % pip3 install pytesseract==0.3.10
al@Als-MacBook-Pro ~ % pip3 install openai-whisper==20231117
If you’re on Windows, you might see an error like this one when installing Whisper:
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.1 as it may crash
You can fix this issue by running pip install "numpy<2" to downgrade NumPy to a compatible version. Be sure to include the double quotation marks.
Additionally, the Whisper package can make use of your computer’s NVIDIA graphics card (GPU) to perform speech recognition faster if you run this command:
C:\Users\al>pip install torch torchvision torchaudio --index-url
https://download.pytorch.org/whl/cu118
Computers with non-NVIDIA brand GPUs, including all MacBooks, don’t support this feature.