import error: no module named bson

不羁的心 提交于 2019-12-10 01:12:13

问题


I'm trying to import json_util in my environment file:

from bson import json_util

I get this import error: no module named bson.

I tried to pip install and uninstall pymongo and bson - but nothing seemed to help. I found out that the bson package is included in pymongo so I installed it explicitly and then I received an EPOCH_AWARE import error.

Currently, only pymongo is installed. It works when I force the virtual environment by using this line:

#subprocess.Popen(['/home/.virtualenvs/simple_worker/bin/python', fileName])

But when I try to run it through the os like this:

os.system('PYTHON_ENV=%s python %s' % (env, fileName))

I get this import error on bson.

Edit: Here is the pip list output

(simple_worker) ➜ worker  pip list                                                                                         ✭ ✱
apache-libcloud (0.17.0)
backports.ssl-match-hostname (3.4.0.2)
gnureadline (6.3.3)
google-api-python-client (1.3.1)
httplib2 (0.9.2)
ipdb (0.8)
ipython (2.3.1)
mock (1.0.1)
oauth2client (1.5.1)
pbr (0.10.7)
pika (0.9.14)
pip (8.0.2)
psutil (2.2.0)
py (1.4.26)
pyaml (15.2.1)
pyasn1 (0.1.7)
pyasn1-modules (0.0.5)
pymongo (3.2.1)
pytest (2.6.4)
pytest-mock (0.4.0)
pytz (2015.4)
PyYAML (3.11)
redis (2.10.3)
requests (2.8.0)
rsa (3.1.4)
setuptools (11.0)
simplejson (3.6.5)
six (1.9.0)
stevedore (1.2.0)
uritemplate (0.6)
urllib3 (1.10)
virtualenv (12.0.7)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.2)

Any ideas?


回答1:


If you don't get the no module named bson error but the EPOCH_AWARE import error , this is due to a name clash between bson and pymongo . In this case you should do these in order :

sudo pip uninstall bson
sudo pip uninstall pymongo
sudo pip install pymongo

you don't need to install bson again




回答2:


Please try on your terminal:

sudo apt-get purge python-bson
sudo apt-get install python-bson

Regards



来源:https://stackoverflow.com/questions/35254975/import-error-no-module-named-bson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!