fc2ブログ

2013-04-21(Sun)

pythonbrew にpython2.7.4+Virtualenvをインストール on Ubuntu12.10

まずpythonbrewでpython2.7.4をインストール

以下のスクリプトを実行すればいい。

#!/bin/sh
cd $HOME/tools

# 1.pythonbrewのインストール
echo 'python brew'
curl -kLO https://github.com/utahta/pythonbrew/raw/master/pythonbrew-install
chmod +x pythonbrew-install
./pythonbrew-install

# 2.PATH追加
echo 'setting bashrc'
echo "export PATH=$PATH:/home/hoge/.pythonbrew/bin"
echo "[[ -s \"$HOME/.pythonbrew/etc/bashrc\" ]] && source \"$HOME/.pythonbrew/etc/bashrc\"" >> ~/.bashrc
source ~/.bashrc

# 3. 2.7.4を追加
echo "[Python-2.7.4]" >> ~/.pythonbrew/etc/config.cfg
echo "url = http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz" >> ~/.pythonbrew/etc/config.cfg
echo "latest = True" >> ~/.pythonbrew/etc/config.cfg
echo ""

# 4.python2.7.4インストール
echo 'python2.7.4'
pythonbrew install 2.7.4



切り替えてみる。

$ pythonbrew switch 2.7.4
Switched to Python-2.7.4
$ python -V
Python 2.7.4



この状態でViretualevnをインストール

$ pip install virtualenv virtualenvwrapper


そうすると以下にインストールされる。

$ ls -l ~/.pythonbrew/pythons/Python-2.7.4/bin
....
virtualenvwrapper.sh
....


virtualenvの実行環境を設定する。

$ vim /home/keisuke/.pythonbrew/etc/bashrc
echo $PATH_PYTHONBREW_CURRENT
if [ -f $PATH_PYTHONBREW_CURRENT/virtualenvwrapper.sh ]; then
source $PATH_PYTHONBREW_CURRENT/virtualenvwrapper.sh
fi
$ source ~/.bashrc


で出来上がり。


スポンサーサイト



2013-03-31(Sun)

mecab-python with Ubuntu12.04 LTS

Ubuntuへmecab-pythonの最新版をインストールしたのでメモる。

環境確認

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"



準備としてひと通りのビルドパッケージをインストール

$ sudo apt-get install build-essential
これをインストールしとかないと以下のようなエラーが発生する。
checking if g++ supports GCC native atomic operations (optional)... no
checking if g++ supports OSX native atomic operations (optional)... no
checking if g++ environment provides all required features... no
configure: error: Your compiler is not powerful enough to compile MeCab.



MeCabのインストール

$ wget http://mecab.googlecode.com/files/mecab-0.996.tar.gz
$ tar xzvf mecab-0.996.tar.gz
$ cd mecab-0.996/
$ ./configure --enable-utf8-only
$ make
$ sudo make install



辞書のインストール

$ wget http://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz
$ tar xzvf mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801/
$ ./configure --with-charset=utf8
$ make
/usr/local/libexec/mecab/mecab-dict-index: error while loading shared libraries: libmecab.so.2: cannot open shared object file: No such file or directory
上記のエラーが出るので以下で対応する。
$ sudo vim /etc/ld.so.conf
include /usr/local/lib
を追加する。
$ sudo ldconfig --->(更新)
$ make
$ sudo make install



mecab-pythonをインストール

$ sudo aptitude install python-dev
$ wget http://mecab.googlecode.com/files/mecab-python-0.996.tar.gz
$ tar xzvf mecab-python-0.996.tar.gz
$ cd mecab-python-0.996/
$ python setup.py build
$ sudo python setup.py install
※mecabとバージョンをあわせましょう。
合わせないと以下のようなエラーが出ます。
MeCab_wrap.cxx: In function ‘const mecab_node_t* mecab_node_t_begin_node_list(mecab_node_t*, size_t)’:
MeCab_wrap.cxx:3083:3: warning: control reaches end of non-void function [-Wreturn-type]
error: command 'gcc' failed with exit status 1


参考:
Ubuntu のデフォルトでは gcc でコンパイルできないので build-essential を入れておく
mecab google code
Rによるテキストマイニング入門

2013-03-24(Sun)

CSRF verification failed. Request aborted With Django1.5

Django1.5を使ってformからPOSTしようとしたら以下のエラーが発生した。

(error内容)

CSRF verification failed. Request aborted.


原因はそのエラー画面の続きに書いてあった。

Your browser is accepting cookies.
・The view function uses RequestContext for the template, instead of Context.
・In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
・If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.


上記3つを満たしていればいいらしい。
(1). Contextの代わりにRequestContextを使え。

render_to_response('news/index.html',
{'entry': entry},
context_instance=RequestContext(request))


OKちゃんと使った。

(2). POSTするときには{% csrf_token %}をつけろ。


{% csrf_token %}
........


OKちゃんとつけた。

(3). Viewにcsrf_protectを使え。

from django.views.decorators.csrf import csrf_protect
@csrf_protect
def search(request):
............


OKちゃんと使った。

再実行すると問題なくPOSTできた。

参考:
Cross Site Request Forgery protection


2013-03-21(Thu)

Django1.5 DEBUG=Falseで500 Error

(環境)

OS: Ubuntu12.04 LTS 64bit
framework: Django1.5


(不具合)

settings.pyのDEBUG=Trueでは問題なしに動く。
DEBUG=Falseにするととたんに"Server 500"となる。


(要因)

1. Status Errorのhtmlファイルがない。
 DEBUG=Trueにすると、デバッグで利用してた静的ファイルが見えなくなり
 エラーファイルはSTATICFILES_DIRSで設定した場所を探しにいくようだ。
2. ALLOWED_HOSTSの設定がない。
 DEBUG=Trueにすると、許可したホスト以外は受け付けなくなるようだ。


(対策)

1. STATICFILES_DIRSで設定したディレクトリに403.html, 404.html, 500.htmlを作成する。
2. ALLOWED_HOSTS = ['*']とする。
これで動いた。



参考:
 Django: Setting DEBUG = False causes 500 Error

2013-03-20(Wed)

Ubuntu12.04 LTSにmysql-pythonをインストール

Ubuntu12.04 LTSにmysql-pythonをインストールしたのでメモ。

基本的にpipで完結すると思ったら何個かエラーが出た。

$ sudo pip install mysql-python
ここでエラー発生
'easy_install -U distribute'.


distributeがないと。インストールはしているのでアップグレードする。

$ sudo pip install --upgrade distribute
Successfully installed distribute


で再挑戦するとまたエラー発生。

$ sudo pip install mysql-python
エラー発生
EnvironmentError: mysql_config not found


mysql_configがないと。
mysqlはapt-get installしたのでmysql_configがないのだと思う。
こういう時はdevを入れる。

$ sudo apt-get install libmysqlclient-dev


再挑戦。

$ sudo pip install mysql-python
Successfully installed mysql-python
Cleaning up...


よし。


プロフィール

kumagonjp2

Author:kumagonjp2
Python,Django,R,Mongo,MySQL,Struts,Spring,データマイニングなどサーバー関係のメモを残していきます。

最新記事
最新コメント
最新トラックバック
月別アーカイブ
カテゴリ
雪が3Dで降るブログパーツ ver2

マウスで見る方向変えられます

検索フォーム
RSSリンクの表示
リンク
ブロとも申請フォーム

この人とブロともになる

QRコード
QR