警告:"IPython历史记录"需要SQLite,您的历史记录将不会保存

问题描述:

我使用的Linux内核3.5.0-21(通用)Ubuntu版本12.10(数量级).我正在尝试使IPython的历史记录起作用.我已经使用pythonbrew和虚拟环境对其进行了设置.在这里,我使用pip来安装IPython.当前,当我在终端中启动IPython时,我得到:

Hi I'm using Ubuntu release 12.10 (quantal) 32-bit with Linux Kernel 3.5.0-21-generic. I'm trying to get IPython's History to work. I've set it up using pythonbrew and a virtual environment. In there I use pip to install IPython. Currently, when I start up IPython in a terminal I get:

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.

在第一行的警告中,我发现了此问题报告,因此我返回并安装了以下内容:

Searching on the warning in the first line, I found this issue report, so I went back and installed the following:

sudo apt-get install libsqlite0 libsqlite0-dev libsqlite3-0 libsqlite3-dev

,然后使用pip删除并重新安装pysqlite

and then removed and reinstalled pysqlite using pip

pip uninstall pysqlite
pip install pysqlite

之后,我想我将通过导入模块来检查安装:

After that I thought I would check the installation by importing the module:

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问题.它不存在或者不在我的PYTHONPATH环境变量中.搜索文件,我得到:

So now it seems the file _sqlite3.so can't be found. That's when I found this SO question. Either it doesn't exist or it's not in my PYTHONPATH environment variable. Searching for the file, I get:

$ 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路径时:

So the file is there, but when I looked in my python path:

import sys
for p in sys.path:
    print p

我的PYTHONPATH中没有

包含_sqlite3.so的上述路径中的任何一个.对于傻笑,我在终端中的PYTHONPATH中添加了/usr/lib/python2.7/lib-dynload路径,然后尝试再次导入sqlite3:

none of the above paths that contain _sqlite3.so were contained in my PYTHONPATH. For giggles, I added the path /usr/lib/python2.7/lib-dynload to my PYTHONPATH in a terminal and then tried to import sqlite3 again:

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中做到这一点.谁能指出我正确的方向?

Uh oh. Now I'm completely stuck. Can anyone help me out? I've also read in a few places that I may have to rebuild Python. I have no idea how to do this in pythonbrew. Can anyone point me in the right direction?

感谢Minrk为我指明了正确的方向.我要做的就是重建python.对于使用pythonbrew的程序,我已经概述了以下步骤.请注意,我已经在问题部分安装了libsqlite3-dev软件包.

Thanks to minrk for pointing me in the right direction. All I had to do was rebuild python. I've outlined the steps below for those that are using pythonbrew. Notice that I already installed the libsqlite3-dev package up in the question section.

首先,在安装了正确版本的python和虚拟环境后,运行以下命令:

First, with the proper version of python and virtual environment loaded up run the command:

$ pip freeze -l > requirements.txt

这为我们提供了一个文本文件列表,其中列出了在pythonbrew中该特定python版本在虚拟环境中安装的所有pip软件包.然后我们从pythonbrew中删除python版本并重新安装(这是"rebuild python"步骤):

This gives us a text file list of all of the pip packages that have been installed in the virtual environment for this particular python release in pythonbrew. Then we remove the version of python from pythonbrew and reinstall it (this is the "rebuild python" step):

$ pythonbrew uninstall 2.7.3
$ pythonbrew install 2.7.3

之后,我们切换到新安装的python版本2.7.3,并创建一个新的虚拟环境(我称为"sci"):

After that, we switch over to the newly installed python version 2.7.3 and create a new virtual environment (which I've called "sci"):

$ pythonbrew switch 2.7.3
$ pythonbrew venv create sci
$ pythonbrew venv use sci

理想情况下,您应该能够运行以下命令:

Ideally you should be able to run the command:

$ pip install -r requirements.txt

,并且根据 pip应该重新安装您在其中安装的所有模块虚拟环境,然后再破坏该版本的python(2.7.3).出于某种原因它对我都不起作用,因此我使用pip个性化手动安装了所有模块.

and according to this pip should reinstall all the modules that you had in the virtual environment before we clobbered that version of python (2.7.3). It didn't work for me for whatever reason so I manually installed all of the modules using pip individuality.

$ ipython --pylab

Python 2.7.3 (default, Jan  5 2013, 18:48:27) 
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.

并且IPython历史记录有效!

and IPython history works!