I have a python package I made. It uses datetime
in multiple places. I notice that on a brand-new python install, I can do import datetime
without issue. Thus, python comes with datetime
built-in.
If I put datetime
in my setup.py as one of the items in install_requires
, it appears to download the pypi package datetime
, even though the builtin package is already available. In some cases, such as with multiprocessing
, the pypi package might require extra things (in the case of the pypimultiprocessing
, it requires gcc-c++
to be installed on my CentOS, while the builtin multiprocessing
has no such requirements).
Questions:
- Should I include builtin packages under
install_requires
if I use them? - Is there an easier way of seeing which packages are builtin and which aren’t other than creating a new
virtualenv
and trying to import things? - Who owns the pypi versions of these builtin packages? Is it some random person, or are these vetted packages provided by the python core team? (I know arbitrary packages can be provided by random people, but I can’t figure out if that’s true for the builtin packages that are also available on pypi.)
2
Answers
Not exactly. It downloads a package called
DateTime
with top-level nameDateTime
, notdatetime
.No.
install_requires
is intended to list external, 3rd-party packages, not the builtin ones, not the standard ones.One is
datetime
, the other isDateTime
.The page https://pypi.org/project/DateTime/ name the author: Zope Foundation and Contributors. And list the current maintainers. The homepage listed is https://github.com/zopefoundation/DateTime
It seems there isn’t a builtin way to do this, but rather than trying to import things, you can run
pkgutil.iter_modules()
to get an iterable with importable modules, which on fresh virtualenv should give you only builtin modules. Then you can compare that list with your own list of used packages.For example, in a new virtualenv: