How to update Python Standard Library packages with pip? How to update Python Standard Library packages with pip? tkinter tkinter

How to update Python Standard Library packages with pip?


pip installs packages from pypi, which does not expose the standard library, which is bundled into Python.

So in theory you should trust your users environment, if they have Python, they should have the whole stadard library.

But some distributions are splitting Python in a few packages for reasons (A minimal Debian already depends on Python, but they don't want Python to pull tk to pull libx11 to pull the life, the universe, and everything).

So in practice some package will be there, and you can trust the distribs for this, like time will always be here. And some package may not be here, like tkinter, in which case you may want to surround the import tkinter by a try to error a nice "Looks like your distribution does not provide tk by default, please install it.".

Be reassured, you won't have to surround every imports by try statements just in case some distribution splitted the stdlib, just tkinter.


Python's Standard Library is called the Standard Library because it is a standard of Python. In other words, if there is no Standard Library installed, the python environment is not python at all.

The Standard Library is tested and released together with each Python release as part of this release (not as an addition or extension).

So, YES, you can expect these libraries to exist if the user has Python installed. Just by definition.


Regarding the upgrades of the built-in libraries: NO, you cannot do this. Because they are part of the python setup, not of the application environment. Python is very tightly bound to the specific code in those libraries. All python apps & libs expect the same behavior of those libraries, even if they are buggy.

In addition to that, you cannot install a module/package with the same name as one of the python's builtins, because it will create the ambiguity on import, and can confuse/break all other libraries which depend on it (or worse, the system applications if you install it into the system python).

However, in some cases you can find the backports of some of the libraries. Usually, they are backported from py3 to py2. Of course, their name is changed.

As an example, you can look into concurrent.features library, which is a handy builtin in py3.2+, but was absent in py2.7.


UPD: Though, as @JulienPalard hints in the comments, some OS distributions can split this standard library to simplify the binary dependencies: e.g., on Debian, Tkinter will be installable separately as python3-tk.

This makes sense, indeed, from the point of view of the binary OS packaging: it is not worth installing the UI parts of the python library if you have no UI at all and want to save the disk space.

However, you are still unable to install it via pip. Because this package is not packaged and available separately on PyPI. This standard library separation is made by the selected OS distributions and is resolved with the means of that OS distribution only.