brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pip show -f lists every file a Python package put on your disk

Python
~/tips/tip-python-pip-show-files

python3 -m pip show -f requests

Shows where an installed Python package lives and lists all the files it installed.

Sometimes you need to know where a package actually lives. Which folder did that command-line script land in, and is this package loaded from the venv or from somewhere else? pip show answers the first part, and with -f it also lists every file the package installed.

Run it through the Python you care about, so you look at the right environment:

python3 -m pip show -f requests

The top part is the familiar metadata: name, version, license, Location (the site-packages folder it sits in), Requires and Required-by. Under Files: comes the full list, taken from the package’s install record. The paths are relative to Location, so a line such as ../../../bin/somecommand tells you the package also dropped a script into the venv’s bin folder.

I like it most for two questions. First, “which command did this package add?”: pipe the output through grep bin/ and you have the answer. Second, “why does Python import the wrong copy?”: the Location line shows at once whether you’re looking at the venv or at a user install in your home folder. It also works with several packages at once (pip show -f requests urllib3), with the blocks separated by ---.

The caveat: pip can only list files when the package came with a record of them. Packages installed by your Linux distribution’s package manager often don’t, and then pip prints Cannot locate RECORD or installed-files.txt instead of a list. Ask dpkg -L or rpm -ql in that case. Also keep in mind that the list covers what was installed, not files the package created later, such as caches or config files in your home folder.

Further reading: pip docs: pip show

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link