pymongo contains multiple top-level directories in the wheel package, which pip simply dumps into the site packages directory, which stomps existing packages with the same name and breaks them in an untraceable way.
Steps to reproduce.
1. Install bson:
pip install bson
This will install some version of bson, like 0.5.10 on Windows at this point for Python 3.10.
2. Go to site packages, whether it's global or in a venv directory, and make a copy of the bson directory.
3. Install pymongo:
pip install pymongo
4. Compare the copied bson directory with the one after the step above and you will see bson significantly modified.
gridfs is installed the same way, but I suppose it can be viewed as an internal Mongo DB project and is less likely to get in the way, but bson is often used on its own to create ObjectId values without having Mongo DB in components that generate those IDs, but otherwise have no DB functionality, and having to inject something like from pymongo.collection import ObjectId makes those components coupled with the database, even though they have nothing to do with it.
Yes, it is possible to import from bson installed by pymongo, but it seems that some type checkers are confused by this because there is no actual bson package installed. That is, if you skip installing bson and just install pymongo, then run pip show bson and it will tell you that bson is not installed, even though it can be imported. This makes it hard to track versions and functionality.
Perhaps a namespace package could be used here to split database layer from BSON, or, maybe, there should be a distinct MongoDB-BSON package, so it can be distinguished from the official BSON package. Either way, other packages shouldn't be mangled by pymongo, even those that are as intrinsic to it as bson.
- duplicates
-
PYTHON-1710 Pollution of the 'bson' namespace upon install of mongo-python-driver
- Closed
-
PYTHON-2805 Blocking pypi 'bson' is not a feasible option
- Closed
- is related to
-
PYTHON-4582 Reach out to bson pypi maintainers with offer of takeover
- Backlog