Python 导入错误:没有名为 bson 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35254975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import error: no module named bson
提问by Liad Amsalem
I'm trying to import json_util
in my environment file:
我正在尝试导入json_util
我的环境文件:
from bson import json_util
I get this import error: no module named bson
.
我收到此导入错误: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.
我尝试 pip install 和卸载 pymongo 和 bson - 但似乎没有任何帮助。我发现 pymongo 中包含 bson 包,所以我明确安装了它,然后我收到了一个EPOCH_AWARE
导入错误。
Currently, only pymongo is installed. It works when I force the virtual environment by using this line:
目前,只安装了 pymongo。当我使用以下行强制虚拟环境时,它会起作用:
#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.
我在 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?
有任何想法吗?
回答by A STEFANI
Please try on your terminal:
请在您的终端上尝试:
sudo apt-get purge python-bson
sudo apt-get install python-bson
Regards
问候
回答by kommradHomer
If you don'tget 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 :
如果您没有收到no module named bson
错误而是EPOCH_AWARE
导入错误,这是由于bson 和 pymongo 之间的名称冲突。在这种情况下,您应该按顺序执行这些操作:
sudo pip uninstall bson
sudo pip uninstall pymongo
sudo pip install pymongo
you don't need to install bson again
你不需要再次安装 bson