【问题标题】:Python2: Installing json_utilPython2:安装 json_util
【发布时间】:2019-03-22 07:32:07
【问题描述】:

我以前是从 bson 导入 json_util:

from bson import json_util

现在我明白了:

ImportError: cannot import name json_util

我现在如何安装 json_util?

【问题讨论】:

    标签: json python-2.7 package bson


    【解决方案1】:

    你做了吗?

    pip install bson

    这不是第 3 方包,它不包括 MongoDB 包中的所有好东西

    https://pypi.org/project/bson/

    json_util(和许多其他实用程序)在 MongoDB Inc 的 pymongo 包中提供。

    pip install pymongo

    https://pypi.org/project/pymongo/

    如 pymongo pypi 页面上所述

    不要从 pypi 安装“bson”包。 PyMongo 自带 自己的 bson 包;做“easy_install bson”安装第三方 与 PyMongo 不兼容的包。

    一些发行版包 MongoDB 的 bson 包 您可能正在使用 RHEL 衍生产品,因为您正在查看 py27。 EPEL 有一个稍微过时的版本,您可以使用

    安装

    yum install python-bson

    http://fedora-epel.mirrors.tds.net/fedora-epel/7/x86_64/Packages/p/python-bson-2.5.2-4.el7.x86_64.rpm

    主线ubuntu也将其打包(同时也将C模块分离到-ext包中)

    https://packages.ubuntu.com/bionic/python-bson

    apt-get install python-bson python-bson-ext

    【讨论】:

      【解决方案2】:

      this issue 中所述并在the detailed answer 中解释,快速解决方法是

      pip uninstall bson
      pip uninstall pymongo
      pip install pymongo
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-02-01
        • 1970-01-01
        • 2021-04-28
        • 2016-11-20
        • 2020-06-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多