A funny little Python dependency trap

February 8, 2025

I was running PuppyAgent’s API service locally. Its code uses from dotenv import load_dotenv to read the project’s .env configuration file. Install whatever’s missing, right? I typed pip install dotenv.

Looking back through my terminal history, I guessed four times. First dotenv, then dotenv-binary, then back to dotenv. On the fourth try I finally got it: python-dotenv. The best part is that the answer had been sitting in the project’s requirements.txt the whole time.

That afternoon I opened a GitHub issue. The person who filed it had also typed pip install dotenv. As luck would have it, PyPI really does have a project by that name. pip found dotenv-0.0.5.tar.gz and got as far as a build dependency error. Someone in the thread had even started to suspect setuptools. The maintainer, theskumar, had a short reply.1

@VrushankiPatel The install command for this library is

pip install python-dotenv

and not

pip install dotenv

Cheers!

It turns out each name belongs to a different step. pip looks up the distribution name, python-dotenv, to find the package to install. Once it’s installed, Python can find it under the name in the code, dotenv. You’d be hard pressed to guess the python- prefix from that import line alone.2

When I checked again later, “Cheers!” had collected 58 👍, 2 😄, 5 🎉, and 1 ❤️. If GitHub ever adds an “I installed dotenv-binary too” button, I know who can cast the first vote.

Footnotes

  1. VrushankiPatel. (2023, July 7). Installing backend dependencies error [Issue #472]. GitHub. Original issue and installation log. Kumar, S. [theskumar]. (2023, July 10). Maintainer’s full reply and reactions. GitHub. Reaction counts as displayed on November 20, 2026. ↩

  2. Python Packaging Authority. (n.d.). Distribution package vs. import package. Python Packaging User Guide. Distribution and import names. ↩

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-02-08). A funny little Python dependency trap. https://caiborui.com/blog/2025-02-08-zh-pip-install-python-dotenv-entrans

@misc{borui2025-38af1b94,
  author = {borui},
  title = {{A funny little Python dependency trap}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-02-08-zh-pip-install-python-dotenv-entrans}
}