pymongo 的安装有效,但在 python3 中导入失败 [英] installation of pymongo works but fails at import in python3

查看:59
本文介绍了pymongo 的安装有效,但在 python3 中导入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行 Ubuntu 12.10 并试图让 pymongo 在 python3 下正常工作.我尝试过的事情:

I'm currently running Ubuntu 12.10 and tried to get pymongo to work properly under python3. Things I have tried:

1. apt-get install python-pymongo
2. python setup.py install #from git source
3. easy_install pymongo
4. easy_install pymongo3
5. pip install pymongo
6. pip install pymongo3 #needed a fix in the download script

我也尽可能地在两次安装之间进行了拆卸和清洁.

I have also removed and cleaned between the installations as best as I could.

如果我导入 pymongo:

If I import pymongo:

In [1]: import pymongo
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-ec8fdd1cd630> in <module>()
----> 1 import pymongo

/usr/local/lib/python3.2/dist-packages/pymongo-2.4.2_-py3.2-linux-x86_64.egg/pymongo/__init__.py in <module>()
     55     return '.'.join(map(str, version_tuple))
     56 
---> 57 version = get_version_string()
     58 """Current version of PyMongo."""
     59 

/usr/local/lib/python3.2/dist-packages/pymongo-2.4.2_-py3.2-linux-x86_64.egg/pymongo/__init__.py in get_version_string()
     51 
     52 def get_version_string():
---> 53     if isinstance(version_tuple[-1], basestring):
     54         return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
     55     return '.'.join(map(str, version_tuple))

NameError: global name 'basestring' is not defined

错误与pymongo 常见问题 但对我来说,我所在的位置并不重要.

The error is the same as pymongo FAQ but for me it doesn't matter where I'm located.

我的理论是pymongo的python2版本误加了python3.

My theory is that the python2 version of pymongo has mistakenly been added python3.

推荐答案

It should work with

It should work with

sudo python3.2 setup.py install

但由于某种原因没有

最好通过

sudo python3 setup.py install #distributed
sudo python3 setup.py install #pip
sudo pip-3.2 install pymongo

这篇关于pymongo 的安装有效,但在 python3 中导入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆