Installing "dotenv" vs "load_dotenv", why?

You’ve stumbled upon the difference between distribution packages and import packages. There’s a nice discussion of the differences between the two in the Packaging User Guide under Distribution package vs. import package. The fact that both use the term “package” causes no end of confusion, especially when you mix in packages for system package managers (e.g. apt), Anaconda packages, etc.

Not too long ago there was a thread collecting some common examples of distribution/import name mismatches:

If you’ve already installed a module and want to find the name of the distribution that provided it, you can use importlib.metadata.packages_distributions to do the reverse lookup. For example, if you want to know what distribution is providing PIL, you can run:

>>> importlib.metadata.packages_distributions()["PIL"]
['Pillow']

Typically a project will declare what distributions it depends on in its pyproject.toml file (or a requirements.txt or setup.py file, particularly for older projects). So if you’re trying to match the packages that some other project is using, those would be good places too look.

3 Likes