import pymongo causes `ImportError: cannot import name BSON`. how do you fix the import error?
Try uninstalling the bson
and pymongo
packages and then reinstalling the pymongo
package. pymongo
installs its own bson
package and I think you've overwritten it with the other bson
package installation and that is probably what is causing your import error.
FYI:
- when you pip install pymongo it also installs bson but it does not ever print a message saying that it is install bson to your virtualenv site-packages
- also pymongo does not list bson as a dep
- also pip -v list does not show that bson is installed
- those bullet points IMO have some code smell (at least print a message stating you are installing bson)
I met the same problem.I think the reason is I install pymongo
and then install bson
.Then I uninstall bson. Then I got this problem.
pip freeze pymongo
it requires Nothing.
So maybe it has its own bson package.
What I solve this problem:
pip uninstall pymongo
pip uninstall bson
and then reinstall pymongo
pip install pymongo
You are returning a list in hello()
. You need to return a string or a Response object, see Flask docs. E.g. convert the list to a string before returning:
return '\n'.join(json_docs)