星期四, 6月 09, 2011

pkg_resources.DistributionNotFound: pip==0.8.2

今天pip突然怪怪的,出現下列訊息:
cacaegg:~ cacaegg$ pip
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.3-fat/egg/pkg_resources.py", line 2607, in
File "build/bdist.macosx-10.3-fat/egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: pip==0.8.2
所以就看一下:
cacaegg:~ cacaegg$ cat /usr/local/bin/pip
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==0.8.2','console_scripts','pip'
__requires__ = 'pip==0.8.3'
import sys
from pkg_resources import load_entry_point

sys.exit(
load_entry_point('pip==0.8.3', 'console_scripts', 'pip')()
)
都改成0.8.3就可以了。

星期二, 4月 26, 2011

bind9 failed to start : resolvconf: Error: /etc/resolv.conf must be a symlink

解法如下:
#cd /etc/resolvconf/
mkdir run
sudo mv ../resolv.conf ./run/
sudo ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
cd /etc/resolvconf/run/
mkdir interface
/etc/init.d/bind9 restart

Okay, let's all.

星期四, 3月 17, 2011

setup numpy and matplotlib under mac os x 10.6

當然先用pip安裝好來
$pip install numpy
$pip install matplotlib
然後想測試時,發生如下的import error
$ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py:62: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5, os, re, shutil, sys, warnings
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
from sets import Set
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 6, in
from matplotlib.figure import Figure, figaspect
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py", line 10, in
from axes import Axes, Subplot, PolarSubplot, PolarAxes
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py", line 6, in
import matplotlib.numerix.npyma as ma
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/numerix/__init__.py", line 166, in
__import__('ma', g, l)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/numerix/ma/__init__.py", line 16, in
from numpy.core.ma import *
ImportError: No module named ma
找不到ma模組,找了一下後發現改位置了
>>> import numpy
>>> print numpy.__version__
1.5.1
>>> print numpy.core.ma
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'ma'
>>> print numpy.ma

>>> quit()
因此去修改下列檔案
$ vim /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/numerix/npyma/__init__.py
$ vim /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/numerix/npyma/__init__.py
裡面有import numpy.core.ma的都改一下
try:
from numpy.core.ma import *
except ImportError:
from numpy.ma import *
最後就可以成功了
$ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py:62: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5, os, re, shutil, sys, warnings
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
from sets import Set
>>> plt.plot([1,2,3,4])
[]
>>> plt.ylabe('some numbers')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'ylabe'
>>> plt.ylabel('some numbers')

>>> plt.show()

Happy hacks ; )

星期二, 3月 15, 2011

Mac OS 安裝MySQL-Python

前幾天升級到Python2.6.6時候原本正常的MySQLdb突然出現如下訊息
$ python -c 'import MySQLdb'
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 19, in
import _mysql
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so
Expected in: dynamic lookup

花了整晚時間東找patch西找版本,真是難搞...

最後想不到去把mysql重新安裝成universal就輕鬆解決了。

pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python

參考

星期日, 2月 20, 2011

利用DNS query查詢Wikipedia

頗有趣的東西,只要查詢xxx.wp.dg.cx的txt record就可以了!

如下指令
bin cacaegg$ dig txt unix.wp.dg.cx
; <<>> DiG 9.6.0-APPLE-P2 <<>> txt unix.wp.dg.cx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 131 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0 ;; QUESTION SECTION: ;unix.wp.dg.cx. IN TXT ;; ANSWER SECTION: unix.wp.dg.cx. 86400 IN TXT "Unix (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe O" "ssanna. Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial... http://a.vu/w:Unix" ;; AUTHORITY SECTION: wp.dg.cx. 3600 IN NS ns.na.l.dg.cx. wp.dg.cx. 3600 IN NS ns.eu.l.dg.cx. ;; Query time: 942 msec ;; SERVER: 192.168.11.1#53(192.168.11.1) ;; WHEN: Sun Feb 20 14:12:53 2011 ;; MSG SIZE rcvd: 483


嫌太多資訊嗎? 加上個short吧。
bin cacaegg$ dig +short txt unix.wp.dg.cx
"Unix (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe O" "ssanna. Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial... http://a.vu/w:Unix"