I used to import json_util from bson:
from bson import json_util
Now I get:
ImportError: cannot import name json_util
How can I install json_util now?
Did you do?
pip install bson
which isntalls this 3rd party package which does not include all the goodies found in MongoDB's package
https://pypi.org/project/bson/
json_util (and a host of other utils) are provided in MongoDB Inc's pymongo package.
pip install pymongo
https://pypi.org/project/pymongo/
As noted on the pymongo pypi page
Do not install the “bson” package from pypi. PyMongo comes with its own bson package; doing “easy_install bson” installs a third-party package that is incompatible with PyMongo.
some distros package MongoDB's bson package You might be on RHEL derivative since you're looking at py27. EPEL has a slightly out of date version you can install with
yum install python-bson
http://fedora-epel.mirrors.tds.net/fedora-epel/7/x86_64/Packages/p/python-bson-2.5.2-4.el7.x86_64.rpm
mainline ubuntu also packages it (and also separates the C module into the -ext package)
https://packages.ubuntu.com/bionic/python-bson
apt-get install python-bson python-bson-ext
As noted in this issue and explained in the detailed answer, the quick fix is to
pip uninstall bson
pip uninstall pymongo
pip install pymongo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With