1

我正在开发一个(python 2.7)flask-mongoengine 应用程序,它使用 bson 的 ObjectId。该项目以一种或另一种方式需要bson。我在尝试部署应用程序的主机上没有 root 访问权限,并且 pip install bson 失败:

-bash-4.1$ pip install bson
Collecting bson
 Using cached bson-1.1.0.tar.gz
  Complete output from command python setup.py egg_info:
  Traceback (most recent call last):
   File "<string>", line 1, in <module>
   File "/tmp/pip-build-BBOawV/bson/setup.py", line 24, in <module>
    import bson
   File "bson/__init__.py", line 66, in <module>
    from . import codec
   File "bson/codec.py", line 28, in <module>
    from .objects import *
   File "bson/objects.py", line 36
    class BSONObject(object, metaclass=ABCMeta):
                                      ^
SyntaxError: invalid syntax

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-BBOawV/bson/

另一方面,https ://api.mongodb.org/python/current/installation.html 声明我不应该使用这个版本的 bson 并依赖 pymongo 的实现。但是,在我安装了 pymongo-3.2.1 的计算机上,我无法导入 pymongo.objectId - 那么我做错了什么以及如何让 bson 使用我的设置?

非常感谢!

4

3 回答 3

2

我遇到了同样的问题,重新安装 PyMongo 修复了 BSON 依赖项:

pip install --upgrade --force-reinstall pymongo
于 2016-07-14T08:29:43.820 回答
0

由于我没有 root 访问权限并且无法安装 bson 的分发版本,因此我选择在我的 DB 文档定义中删除该对象。这为我解决了这个问题,因为它也更干净,但事实正如 Mihai 所说:pip install bson 似乎仅限于 python3 项目。

于 2016-04-28T17:25:54.417 回答
0

我有一个类似的问题。

只需从https://pypi.python.org/pypi/bson/0.4.3下载 tarball 并进行手动安装:

python setup.py install
于 2016-04-22T01:10:16.730 回答