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?
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
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