skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search