嗨,我正在使用 Ubuntu 版本 12.10(量子)32 位和 Linux 内核 3.5.0-21-generic。我正试图让 IPython 的历史工作。我已经使用 pythonbrew 和虚拟环境进行了设置。在那里我使用 pip 安装 IPython。目前,当我在终端中启动 IPython 时,我得到:
WARNING: IPython History requires SQLite, your history will not be saved
Python 2.7.3 (default, Nov 8 2012, 18:25:10)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
搜索第一行的警告,我发现了这个问题报告,所以我回去安装了以下内容:
sudo apt-get install libsqlite0 libsqlite0-dev libsqlite3-0 libsqlite3-dev
然后使用 pip 删除并重新安装 pysqlite
pip uninstall pysqlite
pip install pysqlite
之后我想我会通过导入模块来检查安装:
Python 2.7.3 (default, Nov 8 2012, 18:25:10)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
所以现在似乎找不到文件_sqlite3.so。那是我发现这个 SO question的时候。它要么不存在,要么不在我的 PYTHONPATH 环境变量中。搜索文件,我得到:
$ locate _sqlite3.so
/home/me/Desktop/.dropbox-dist/_sqlite3.so
/home/me/epd/lib/python2.7/lib-dynload/_sqlite3.so
/usr/lib/python2.7/lib-dynload/_sqlite3.so
所以文件在那里,但是当我查看我的python路径时:
import sys
for p in sys.path:
print p
上述包含 _sqlite3.so 的路径均未包含在我的 PYTHONPATH 中。对于傻笑,我在终端中将路径 /usr/lib/python2.7/lib-dynload 添加到我的 PYTHONPATH 中,然后尝试再次导入 sqlite3:
Python 2.7.3 (default, Nov 8 2012, 18:25:10)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("/usr/lib/python2.7/lib-dynload")
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: /usr/lib/python2.7/lib-dynload/_sqlite3.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8
哦哦。现在我完全被困住了。谁能帮我吗?我还阅读了一些我可能需要重建 Python 的地方。我不知道如何在 pythonbrew 中做到这一点。谁能指出我正确的方向?