问题描述
我正在尝试在环境文件中导入 json_util
:
I'm trying to import json_util
in my environment file:
from bson import json_util
我收到此导入错误:没有名为模块的文件bson
。
我尝试安装和卸载pymongo和bson-但似乎无济于事。我发现pymongo中包含bson软件包,因此我明确安装了该软件包,然后收到 EPOCH_AWARE
导入错误。
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.
当前,仅安装pymongo。当我通过使用以下行强制虚拟环境时,它会起作用:
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])
但是当我尝试通过os来运行它时
But when I try to run it through the os like this:
os.system('PYTHON_ENV=%s python %s' % (env, fileName))
我在bson上收到此导入错误。
I get this import error on bson.
编辑:这是点列表的输出
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)
任何
推荐答案
如果您不得到没有名为bson
错误,但 EPOCH_AWARE
导入错误,这是由于bson和pymongo之间的名称冲突引起的。在这种情况下,您应该按以下顺序进行操作:
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
您无需再次安装bson
you don't need to install bson again
这篇关于导入错误:没有名为bson的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!