Reputation: 11484
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:
install_requires
if I use them?virtualenv
and trying to import things?Upvotes: 0
Views: 778
Reputation: 109
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?
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:
import pkgutil
fulldeps = ['datetime', 'multiprocessing', 'tensorflow']
builtin_modules = [module.name for module in pkgutil.iter_modules()]
real_deps = [module for module in fulldeps if module not in builtin_modules]
print(real_deps)
['tensorflow']
Upvotes: 1
Reputation: 94932
it appears to download the pypi package datetime
Not exactly. It downloads a package called DateTime
with top-level name DateTime
, not datetime
.
Should I include builtin packages under
install_requires
if I use them?
No. install_requires
is intended to list external, 3rd-party packages, not the builtin ones, not the standard ones.
Is there an easier way of seeing which packages are builtin and which aren't?
One is datetime
, the other is DateTime
.
Who owns the pypi versions of these builtin packages?
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
Upvotes: 2