2015年7月26日 星期日

[胡言亂語] Android Studio

最近在找 Android Studio 的資料, 發現簡中的文件比繁中多太多了, 雖然是早已經知道的結果, 可是還是不禁要感嘆一下 reference: Android Studio系列教程

2015年7月25日 星期六

[Tips] 切換 Python 版本

電腦裡裝了很多版本的 Python
python             python2.6          python2.7          python3.4-config   python3.4m-config  
python2            python2.6-config   python3.4          python3.4m         python-config      
預設是使用超級舊的 2.6.5, 有些模組功能不支援, 例如 subprocess 的 check_output 只在 python2.7 以後才能使用
python --version
Python 2.6.5
我們可以利用 update-alternatives 切換 python 的版本 先查一下可使用的版本, 真糟糕不能用
update-alternatives --list python
update-alternatives: error: no alternatives for python.
加入 2.6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1
update-alternatives: using /usr/bin/python2.6 to provide /usr/bin/python (python) in auto mode.
加入 2.7
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode.
加入 3.4
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 3
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode.
再查一下可使用的版本
update-alternatives --list python
/usr/bin/python2.6
/usr/bin/python2.7
/usr/bin/python3.4
可以很高興的切換版本了
sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.4   3         auto mode
  1            /usr/bin/python2.6   1         manual mode
  2            /usr/bin/python2.7   2         manual mode
  3            /usr/bin/python3.4   3         manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode.
看看現在使用的 python 版本吧
python --version
Python 2.7.6
這套工具特別適合程式語言版本的切換, Java 更是需要阿

最近發生了一個趣事, 切換版本以後 apt-get 會用到 python 的指令都爛掉了, 錯誤訊息如下:
After this operation, 0B of additional disk space will be used.
(Reading database ... 417151 files and directories currently installed.)
Preparing to replace python-pkg-resources 0.6.10-4ubuntu1 (using .../python-pkg-resources_0.6.10-4ubuntu1_all.deb) ...
Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2300, in 
    main()
  File "/usr/bin/pycentral", line 2294, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1653, in run
    runtimes = get_installed_runtimes(with_unsupported=True)
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: warning: old pre-removal script returned error exit status 1
dpkg - trying script from the new package instead ...
Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2300, in 
    main()
  File "/usr/bin/pycentral", line 2294, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1653, in run
    runtimes = get_installed_runtimes(with_unsupported=True)
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: error processing /var/cache/apt/archives/python-pkg-resources_0.6.10-4ubuntu1_all.deb (--unpack):
 subprocess new pre-removal script returned error exit status 1
Traceback (most recent call last):
  File "/usr/bin/pycentral", line 2300, in 
    main()
  File "/usr/bin/pycentral", line 2294, in main
    rv = action.run(global_options)
  File "/usr/bin/pycentral", line 1477, in run
    runtimes = get_installed_runtimes()
  File "/usr/bin/pycentral", line 278, in get_installed_runtimes
    default_version = pyversions.default_version(version_only=True)
  File "/usr/share/pycentral-data/pyversions.py", line 172, in default_version
    raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default
ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/python-pkg-resources_0.6.10-4ubuntu1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
拜了咕狗以後, 才發現還是要把 default python 路徑(/usr/bin/python)指到一個喜歡的人上面(python2.6)
sudo ln -sf /usr/bin/python2.6 /usr/bin/python

2015年7月9日 星期四

[計算機概論] The TTY demystified

這篇有很詳盡的介紹 TTY 的歷史, 好像叫 demystified 的都很厲害?

貼幾張圖吧: