2012年4月7日 星期六

執行apt-get install 指令安裝出現問題?有解決方案!

[stayhigh@:~$] sudo apt-get install aptitude
[sudo] password for stayhigh:
正在讀取套件清單... 完成
正在重建相依關係        
正在讀取狀態資料... 完成
aptitude 已經是最新版本了。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
3 個沒有完整得安裝或移除。
此操作完成之後,會多佔用 0B 的磁碟空間。
正在設定 linux-image-2.6.32-40-generic (2.6.32-40.87) ...
Running depmod.
update-initramfs: Generating /boot/initrd.img-2.6.32-40-generic
Running postinst hook script /usr/sbin/update-grub.
/etc/default/grub: 1: f#: not found
User postinst hook script [/usr/sbin/update-grub] exited with value 127
dpkg:在處理 linux-image-2.6.32-40-generic (--configure) 時發生錯誤:
 子程序 installed post-installation script 傳回了錯誤退出狀態 127
dpkg:因相依問題,不能設定 linux-image-generic:
 linux-image-generic 相依於 linux-image-2.6.32-40-generic﹔然而:
  linux-image-2.6.32-40-generic 套件尚未設定。
dpkg:在處理 linux-image-generic (--configure) 時發生錯誤:
 相依問題 - 保留為未設定
dpkg:因相依問題,不能設定 linux-generic:
 linux-generic 相依於 linux-image-generic (= 2.6.32.40.47)﹔然而:
  linux-image-generic 套件尚未設定。
dpkg:在處理 linux-generic (--configure) 時發生錯誤:
 相依問題 - 保留為未設定
No apport report written because the error message indicates its a followup error from a previous failure.
                          No apport report written because the error message indicates its a followup error from a previous failure.
                                                    在處理時有錯誤發生:
 linux-image-2.6.32-40-generic
 linux-image-generic
 linux-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

解決方案:

由訊息中可知道 問題出現於 /etc/default/grub: 1: f#: not found
檢查/etc/default/grub發現文件中第1行多打了一個字元f
將其刪除後儲存 並執行 sudo update-grub
即可使用之。
現在重新使用指令apt-get install 確認是否問題以排除
[stayhigh@:~$] sudo apt-get install aptitude
正在讀取套件清單... 完成
正在重建相依關係          
正在讀取狀態資料... 完成
aptitude 已經是最新版本了。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。

2012年3月9日 星期五

讓Python支持Tab補齊

使用Bash一段時間後,你會在需要輸入命令的地方,習慣性的按Tab補齊,毫無疑問Tab補齊是一個相當棒的功能,強大的Python當然也支持,只不過你需要一點點hack 。
首先檢查一下你的Python是否安裝了readline與rlcompleter這兩個module。如果你用的發行版不是特別陳舊,那默認的Python安裝都會包含。
現在打開Python,導入這兩個module,然後激活Tab補齊,你就可以使用它了。
>>> import readline
>>> import rlcompleter
>>> readline.parse_and_bind('tab: complete')
>>> readline.__
readline.__class__ readline.__name__
readline.__delattr__ readline.__new__
readline.__dict__ readline.__reduce__
readline.__doc__ readline.__reduce_ex__
readline.__file__ readline.__repr__
readline.__getattribute__ readline.__setattr__
readline.__hash__ readline.__str__
readline.__init__
如果你希望每次打開Python都能自動激活Tab補齊,只需把它加到Python的啟動腳本里。
如果你還沒有定制自己的Python啟動腳本,現在就建立一個吧,然後把它加到bash的初始化腳本(~/.bashrc)裡:
export PYTHONSTARTUP=~/.pythonrc.py
下面是.pythonrc.py的內容
1try :
2    import readline
3except ImportError:
4    print "Module readline not available." )
5else :
6    import rlcompleter
7    readline.parse_and_bind( "tab: complete" )
在Linux下,這個功能Python2和3都支持。關於readline與rlcompleter這兩個module的詳細信息,可以查看Python的手冊