Python

Packaging & Distribution

29 flashcards · answers and spaced-repetition review in the KnowCard app

You import a function from a single .py file. Is that file a module, a package, or a distribution?
A teammate says "just pip install PIL" but the import is import PIL and it fails. Why can pip install <name> and import <name> use different names?
What's the practical difference between a wheel (.whl) and an sdist (source tarball, .tar.gz) when you run pip install?
Installing a package with a C extension fails with "error: command 'gcc' failed". What does that tell you about what pip downloaded, and what's the usual fix?
For a brand-new project, should you write a setup.py or a pyproject.toml? What's the relationship between them?
Why is running python setup.py install (or sdist/bdist_wheel) considered the wrong way to build/install today, and what replaced each?
What does PyPI stand for, and which tool publishes TO it versus installs FROM it?
What does pip freeze > requirements.txt capture, and why is it different from a hand-written requirements file?
In requirements, what's the difference between requests>=2.0 and requests==2.31.0, and why pin exact versions?
You changed your library's source, reinstalled with pip install ., but import mylib still runs the OLD code. What install mode avoids this during development?
Under semantic versioning, a dependency goes from 1.4.2 to 2.0.0. What does that signal versus a bump to 1.5.0 or 1.4.3?
How do you install a specific exact version of a package with pip, and how do you install the wheel from a local file?
Older docs distribute a .egg; a colleague asks if eggs and wheels are interchangeable. What's the difference and what should new projects build?
A package ships only an sdist (no wheel). Why might a fresh pip install of it fail for one user but succeed for another on the same package version?
What command builds the distribution artifacts (sdist + wheel) for a project that has a pyproject.toml?
In setup(), what's the difference between install_requires and dependency_links?
With a legacy setuptools setup.py, which argument builds a wheel versus an RPM versus an egg — and what extra package does the wheel need?
Running python setup.py sdist on Windows gives you a .zip, but your Linux colleague gets a .tar.gz from the same command. Why, and how would you force a specific format?
An old tutorial tells you to build your distribution with distutils from the standard library. Why shouldn't you rely on that today?
What does pip install -r requirements.txt do?
You want to hand a Windows user a single .exe that runs even though they have no Python installed. setuptools wheels won't do this — what tool will, and what ends up in the output folder?
In a setuptools setup.py you see both py_modules=[...] and packages=[...]. When do you use each?
Your modules live under a src/ folder, not the project root, so setup can't find them. Which setup() parameter fixes this, and how do you avoid listing packages by hand?
You ship a command-line tool file alongside your library. Which setup() parameter includes it, and what does setuptools quietly fix about it on install?
Your package needs data files like hello.txt bundled next to its code. How do you include them via setup(), and what's the rule about the paths you write?
After installing packages with pip, which commands list what you have and show details about one package — and how do you remove one?
On a Linux box with its own system package manager, why might you add --user to pip install, and what does it change?
Both pip and conda install Python packages. What can conda do that pip fundamentally can't?
In conda, how do you pin an exact package version, and what do you do when a package (or newer version) isn't in the official Anaconda channel?

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play