2015-06-03 42 views
16

我無法確定ipython在哪裏存儲它的歷史記錄。ipython的歷史文件在哪裏

a。沒有〜/ .pythonhistory:

12:49:00/dashboards $ll ~/.py* 
ls: /Users/steve/.py*: No such file or directory 

b。在python啓動文件中沒有什麼特別的:

12:49:07/dashboards $echo $PYTHONSTARTUP 
/shared/.pythonstartup 
12:49:43/dashboards $cat /shared/.pythonstartup 
import rlcompleter 
import readline 

readline.parse_and_bind("tab: complete") 

c。但是:當我啓動ipython時,我確實有很多歷史可用。

那麼,歷史被存儲在哪裏?

UPDATE從@Stefano答案領導的正確方法:這裏是實際路徑

13:30:05/shared $ll ~/.ipython/profile_default/history.sqlite 
-rw-r--r-- 1 steve staff 372736 Jun 3 12:48 /Users/steve/.ipython/profile_default/history.sqlite 
+0

相關:如果你想IPython的歷史記錄導出到文本文件,做'%歷史-g -f filename' –

+0

@ChristianLong PLS做出回答,我會給予好評。 – javadba

+0

@javadba,爲什麼不改進/完成最好的現有答案? – Dirk

回答

17

IPython的歷史記錄存儲在位於配置文件目錄SQLite數據庫。默認情況下:

~/.ipython/profile_default/history.sqlite 

舊版本(1.x中)存儲文件數據,~/.config/ipython,至少在符合XDG basedir specs(即大多數Linux發行版)平臺。

無論如何,你可以找到與該配置文件目錄:

$ ipython locate profile default 

注意,歷史數據庫IPython的和IPython3之間共享,如果兩者都安裝。

+0

根據文檔它應該在['〜/ .ipython'](http://ipython.org/ipython-doc/stable/config/intro.html#the-ipython-directory) – mata

+1

@mata顯然他們改變了在2.x系列中的統一默認位置。我在挖掘源代碼以供參考,但我想維基更有意義。感謝指針。 –

+1

確認更新的版本使用〜/ .ipython/profile_XXXX/history.sqlite路徑 – economy

24

如果您希望在純文本文件中使用IPython歷史記錄,則可以自行導出它。

%history -g -f filename 
+1

我發現沒有'-g'也適合我。 '-g'是做什麼的? – zyxue

+1

沒有'-g',它會導出當前會話的歷史記錄。使用'-g',它會爲所有會話導出歷史記錄。我發現'-g'的唯一文檔是通過在IPython shell中輸入'%quickref'。 –

+0

那麼ipython從安裝和首次使用時記錄所有會話歷史記錄?這有點令人驚訝...... – zyxue