Software Workshop

setuptools 설치

wget https://bootstrap.pypa.io/ez_setup.py -O - | python

이러면 setuptools가 설치된다.
이후로는 easy_install만 실행하면 패키지 관리가 된다.

easy_install BeautifulSoup
easy_install mechanize
easy_install pycassa

easy_install은 기존 설치된 패키지를 upgrade하는 기능도 제공한다.

easy_install --upgrade mechanize

pip 설치

pip는 easy_install의 대체품이다.

wget -O - https://bootstrap.pypa.io/get-pip.py | python 

패키지 업데이트

업데이트 스크립트

#!/bin/bash
 
PACKAGE_LIST=`find /Library/Python/2.6/site-packages -type d -maxdepth 1 | cut -d/ -f6 | grep -v ^$ | cut -d- -f1 | sort -u`
 
echo "---------------------------------------------------------------"
echo -n "Start at "; date
 
for package in $PACKAGE_LIST; do
 easy_install --upgrade $package 
done
 
echo -n "End at "; date
echo "---------------------------------------------------------------"
echo

이 스크립트는 그대로 사용할 수 없고 패키지가 설치되는 site-packages를 찾아서 그 경로를 적어줄 필요가 있다. 현재 사용하는 OS나 파이썬 버전에 따라 경로가 달라지므로 직접 찾아볼 필요가 있다. 대개는 python 바이너리가 설치된 디렉토리의 상위 디렉토리에서 lib/python-버전/site-packages에 위치한다.

패키지 설치

pip를 설치하고 나면 이용하여 PyPI(Python Package Index)에서 패키지를 검색하여 설치할 수 있다.

pip search xml
ll-xist - Extensible HTML/XML generator, cross-platform templating language, Oracle utilities and various other tools
lxml - Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.
Chameleon - Fast HTML/XML Template Compiler.
generateDS - Generate Python data structures and XML parser from Xschema
archgenxml - UML to code generator for Plone
libxml2dom - PyXML-style API for the libxml2 Python bindings
bridge - General purpose XML library for CPython and IronPython
Amara - Library for XML processing in Python
xmltopy - Utilities for manipulating XML
html - simple, elegant HTML, XHTML and XML generation
kid - A simple and pythonic XML template language
dexml - a dead-simple Object-XML mapper for Python
yaxl - Yet Another (Pythonic) XML Library
rpc4django - Handles JSONRPC and XMLRPC requests easily with Django
.
.
.
pip install libxml2dom

easy_install 업그레이드

setuptools와 easy_install을 업그레이드해주는 스크립트를 다운로드하여 실행하면 된다.

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py

Troubleshooting

ssl이나 https에서 에러가 발생하면

시스템에 openssl-devel 패키지를 설치한 다음에 python을 다시 빌드한다. (configure 옵션에 추가할 필요없음)

from urllib import HTTPSHandler
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name HTTPSHandler

pip list에서 AssertionError가 발생하면

pip install -U distribute

File "/usr/local/lib/python2.7/dist-packages/pip/init.py", line 194, in from_dist
assert len(specs) == 1 and specs[0]0 == '=='
AssertionError

egg_info 명령이 유효하지 않다고 에러가 발생하면

pip install -U setuptools

error: invalid command 'egg_info'
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_terzeron/pysqlite
Storing debug log for failure in /home1/terzeron/.pip/pip.log