Python 2.6, PIL, Django 1.3 e MySQLdb no CentOS 5.5
Instalar um ambiente Django razoavelmente moderno em um CentOS 5.5 (e, presumivelmente, em um Red Hat 5.x) pode não ser uma tarefa trivial - envolve, por exemplo, algumas decisões que precisam ser tomadas e, às vezes, um ou outro sacrifício que precisa ser feito.
Vamos começar com uma instalação mínima do CentOS. No nosso caso, escolhemos o 5.5 por ser o mais novo. Baixado o .iso (eu baixei o instalador via rede, que é minúsculo), rodado o instalador e instalado um CentOS 5.5 básico, podemos entrar no seu terminal e começar a brincar.
Last login: Fri Apr 8 19:29:35 2011 [root@centos ~]# python Python 2.4.3 (#1, Sep 3 2009, 15:37:12) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [root@centos ~]#
O Python 2.4 que vem instalado no CentOS 5 (e no RHEL 5) não é o ideal. E não é por vários motivos: nossas aplicações Django podem querer instalar bibliotecas que conflitem com as bibliotecas que fazem parte da instalação do Python padrão do Red Hat e, como essa instalação é parte muito importante do sistema (o sistema de gerenciamento de pacotes depende dele, por exemplo). é bom não quebrá-lo
Felizmente, o pessoal do Fedora mantém um repositório de extras, o EPEL, com versões mais novas de partes do RHEL 5 (e que servem no CentOS) preparadas de modo a não conflitar com as partes originais do sistema.
Instalar esse repositório entre as fontes de software usuais do yum é bastante simples.
[root@centos ~]# wget http://mirrors.ucr.ac.cr/epel/5/i386/epel-release-5-3.noarch.rpm --2011-04-08 19:36:47-- http://mirrors.ucr.ac.cr/epel/5/i386/epel-release-5-3.noarch.rpm Resolving mirrors.ucr.ac.cr... 163.178.174.25 Connecting to mirrors.ucr.ac.cr|163.178.174.25|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 11989 (12K) [application/x-redhat-package-manager] Saving to: `epel-release-5-3.noarch.rpm' 100%[======================================>] 11,989 31.5K/s in 0.4s 2011-04-08 19:36:48 (31.5 KB/s) - `epel-release-5-3.noarch.rpm' saved [11989/11989] [root@centos ~]# rpm -i epel-release-5-3.noarch.rpm warning: epel-release-5-3.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Aqui ele nos avisa que a assinatura criptográfica do EPEL não bate com as chaves nas quais nossa instalação confia. Não vou me dar o trabalho de importar essas chaves porque eu quero ser avisado quando for instalar algo que não faça parte do CentOS padrão. Agora vamos ver que versão de Python temos no EPEL:
[root@centos ~]# yum search python26 Loaded plugins: fastestmirror Determining fastest mirrors * addons: centos.ufms.br * base: centos.ufms.br * epel: mirror.karneval.cz * extras: holmes.umflint.edu * updates: centos.ufms.br addons | 951 B 00:00 addons/primary | 202 B 00:00 base | 1.1 kB 00:00 base/primary | 954 kB 00:00 base 2683/2683 epel | 3.7 kB 00:00 epel/primary_db | 3.0 MB 00:02 extras | 2.1 kB 00:00 extras/primary_db | 181 kB 00:00 updates | 1.9 kB 00:00 updates/primary_db | 190 kB 00:00 ============================== Matched: python26 =============================== dpm-python26.i386 : Disk Pool Manager (DPM) python bindings lfc-python26.i386 : LCG File Catalog (LFC) python bindings python26.i386 : An interpreted, interactive, object-oriented programming : language
A saída vai continuar. No meio dela veremos isso aqui (que tem o easy_install desse Python - nós queremos usá-lo)
python26-distribute.noarch : Easily build and distribute Python packages
E vemos que temos uma PIL (Python Imaging Library) já pronta. Isso é ótimo pra nós.
python26-imaging.i386 : Python's own image processing library
Nem tudo aqui são boas notícias - o repositório EPEL não tem um Python 2.7. Para termos o 2.7 teríamos que compilar nosso próprio Python e a PIL correspondente. O Pyhon, por si, não é grande problema, mas compilar uma PIL pode dar mais trabalho do que você quer. Outra coisa - tudo o que você instala fora do gerenciamento de pacotes tem que ser mantido por você. O Yum acha, sozinho, updates e pode aplicá-los, mas isso não vale pra o que você instala por conta própria. O pip também ajuda a instalar/atualizar bibliotecas do Python, mas o processo é manual.
É por isso que vamos ficar com o Python 2.6. Decidido isso, podemos instalar pedaços que estão no EPEL (eu não preciso mencionar o python26, porque os outros dois dependem dele.
Mesmo dentro do EPEL, nem tudo do que vimos é bom. Ficaram faltando o driver do MySQL e o Django (que não estão na lista). Vamos resolver isso mais para a frente, de outro jeito.
[root@centos ~]# yum install python26-imaging.i386 python26-distribute.noarch Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: centos.ufms.br * base: centos.ufms.br * epel: mirror.karneval.cz * extras: holmes.umflint.edu * updates: centos.ufms.br Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package python26-distribute.noarch 0:0.6.10-4.el5 set to be updated --> Processing Dependency: /usr/bin/python2.6 for package: python26-distribute ---> Package python26-imaging.i386 0:1.1.7-4.el5 set to be updated --> Processing Dependency: libpython2.6.so.1.0 for package: python26-imaging --> Processing Dependency: liblcms.so.1 for package: python26-imaging --> Running transaction check ---> Package lcms.i386 0:1.18-0.1.beta1.el5_3.2 set to be updated ---> Package python26.i386 0:2.6.5-6.el5 set to be updated --> Processing Dependency: libffi.so.5 for package: python26 ---> Package python26-libs.i386 0:2.6.5-6.el5 set to be updated --> Running transaction check ---> Package libffi.i386 0:3.0.5-1.el5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: python26-distribute noarch 0.6.10-4.el5 epel 510 k python26-imaging i386 1.1.7-4.el5 epel 477 k Installing for dependencies: lcms i386 1.18-0.1.beta1.el5_3.2 base 176 k libffi i386 3.0.5-1.el5 epel 21 k python26 i386 2.6.5-6.el5 epel 6.5 M python26-libs i386 2.6.5-6.el5 epel 667 k Transaction Summary ================================================================================ Install 6 Package(s) Upgrade 0 Package(s) Total download size: 8.3 M Is this ok [y/N]: y
Dizendo "y", ele continua instalando o resto
Downloading Packages: (1/6): libffi-3.0.5-1.el5.i386.rpm | 21 kB 00:00 (2/6): lcms-1.18-0.1.beta1.el5_3.2.i386.rpm | 176 kB 00:00 (3/6): python26-imaging-1.1.7-4.el5.i386.rpm | 477 kB 00:01 (4/6): python26-distribute-0.6.10-4.el5.noarch.rpm | 510 kB 00:00 (5/6): python26-libs-2.6.5-6.el5.i386.rpm | 667 kB 00:01 (6/6): python26-2.6.5-6.el5.i386.rpm | 6.5 MB 00:15 -------------------------------------------------------------------------------- Total 359 kB/s | 8.3 MB 00:23 warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6 epel/gpgkey | 1.7 kB 00:00 Importing GPG key 0x217521F6 "Fedora EPEL <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL Is this ok [y/N]: y warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897 base/gpgkey | 1.5 kB 00:00 Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : lcms 1/6 Installing : libffi 2/6 Installing : python26 3/6 Installing : python26-libs 4/6 Installing : python26-distribute 5/6 Installing : python26-imaging 6/6 Installed: python26-distribute.noarch 0:0.6.10-4.el5 python26-imaging.i386 0:1.1.7-4.el5 Dependency Installed: lcms.i386 0:1.18-0.1.beta1.el5_3.2 libffi.i386 0:3.0.5-1.el5 python26.i386 0:2.6.5-6.el5 python26-libs.i386 0:2.6.5-6.el5 Complete!
Fizemos um bom progresso até agora.
[root@centos ~]# which easy_install-2.6 /usr/bin/easy_install-2.6
Vimos que o easy_install está onde devia estar
[root@centos ~]# python2.6 Python 2.6.5 (r265:79063, Feb 28 2011, 21:55:56) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Image >>> i = Image.open('/usr/share/gtk-2.0/demo/background.jpg') >>> i.size (400, 400) >>>
E que o Python 2.6 tem a PIL funcionando e que entende um JPEG. Agora vamos usar o easy_install para instalar o pip. O easy_install tem um defeito sério - não ter um easy_uninstall. Esse problema é resolvido pelo pip, e é por isso que vamos instalá-lo usando o easy_install. Tanto easy_install quanto pip usam repositórios que não são os do sistema. Foi por isso que instalamos um segundo Python que não é usado por mais ninguém além de nós.
[root@centos ~]# easy_install-2.6 pip Searching for pip Reading http://pypi.python.org/simple/pip/ Reading http://pip.openplans.org Reading http://www.pip-installer.org Best match: pip 1.0 Downloading http://pypi.python.org/packages/source/p/pip/pip-1.0.tar.gz# md5=327fc4a03df189506966e15021730550 Processing pip-1.0.tar.gz Running pip-1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-5H9hmm/pip-1.0/ egg-dist-tmp-ZW3H2k warning: no files found matching '*.html' under directory 'docs' warning: no previously-included files matching '*.txt' found under directory 'docs/_build' no previously-included directories found matching 'docs/_build/_sources' Adding pip 1.0 to easy-install.pth file Installing pip script to /usr/bin Installing pip-2.6 script to /usr/bin Installed /usr/lib/python2.6/site-packages/pip-1.0-py2.6.egg Processing dependencies for pip Finished processing dependencies for pip
Como não encontramos um pacote já compilado pro driver MySQL do Python, precisamos instalar um compilador C++, os headers do Python 2.6 e do MySQL (vamos precisar disso para compilar o driver Python do MySQL nós mesmos). Não se deixe intimidar - afinal, você é um sysadmin.
[root@centos ~]# yum install rpm-build gcc-c++ python26-devel mysql-devel Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: centos.ufms.br * base: centos.ufms.br * epel: mirror.karneval.cz * extras: holmes.umflint.edu * updates: centos.ufms.br Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package gcc-c++.i386 0:4.1.2-50.el5 set to be updated --> Processing Dependency: libstdc++-devel = 4.1.2-50.el5 for package: gcc-c++ --> Processing Dependency: libstdc++ = 4.1.2-50.el5 for package: gcc-c++ --> Processing Dependency: gcc = 4.1.2-50.el5 for package: gcc-c++ ---> Package mysql-devel.i386 0:5.0.77-4.el5_5.5 set to be updated --> Processing Dependency: mysql = 5.0.77-4.el5_5.5 for package: mysql-devel --> Processing Dependency: libmysqlclient.so.15 for package: mysql-devel --> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-devel --> Processing Dependency: openssl-devel for package: mysql-devel ---> Package python26-devel.i386 0:2.6.5-6.el5 set to be updated ---> Package rpm-build.i386 0:4.4.2.3-22.el5 set to be updated --> Processing Dependency: popt = 1.10.2.3-22.el5 for package: rpm-build --> Processing Dependency: rpm = 4.4.2.3-22.el5 for package: rpm-build --> Processing Dependency: rpm-libs = 4.4.2.3-22.el5 for package: rpm-build --> Processing Dependency: elfutils for package: rpm-build --> Running transaction check ---> Package elfutils.i386 0:0.137-3.el5 set to be updated --> Processing Dependency: elfutils-libs-i386 = 0.137-3.el5 for package: elfutils --> Processing Dependency: libdw.so.1(ELFUTILS_0.127) for package: elfutils --> Processing Dependency: libdw.so.1(ELFUTILS_0.122) for package: elfutils --> Processing Dependency: libasm.so.1 for package: elfutils --> Processing Dependency: libdw.so.1(ELFUTILS_0.130) for package: elfutils --> Processing Dependency: libdw.so.1 for package: elfutils --> Processing Dependency: libasm.so.1(ELFUTILS_1.0) for package: elfutils --> Processing Dependency: libdw.so.1(ELFUTILS_0.126) for package: elfutils ---> Package gcc.i386 0:4.1.2-50.el5 set to be updated --> Processing Dependency: cpp = 4.1.2-50.el5 for package: gcc --> Processing Dependency: libgcc >= 4.1.2-50.el5 for package: gcc --> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc --> Processing Dependency: libgomp >= 4.1.2-50.el5 for package: gcc ---> Package libstdc++.i386 0:4.1.2-50.el5 set to be updated ---> Package libstdc++-devel.i386 0:4.1.2-50.el5 set to be updated addons/filelists | 195 B 00:00 base/filelists | 2.9 MB 00:01 epel/filelists_db | 4.5 MB 00:09 extras/filelists_db | 195 kB 00:00 updates/filelists_db | 796 kB 00:06 ---> Package mysql.i386 0:5.0.77-4.el5_5.5 set to be updated --> Processing Dependency: perl(DBI) for package: mysql ---> Package openssl-devel.i386 0:0.9.8e-12.el5_5.7 set to be updated --> Processing Dependency: openssl = 0.9.8e-12.el5_5.7 for package: openssl-devel --> Processing Dependency: zlib-devel for package: openssl-devel --> Processing Dependency: krb5-devel for package: openssl-devel --> Processing Dependency: popt = 1.10.2.3-18.el5 for package: rpm-python ---> Package popt.i386 0:1.10.2.3-22.el5 set to be updated ---> Package rpm.i386 0:4.4.2.3-22.el5 set to be updated ---> Package rpm-libs.i386 0:4.4.2.3-22.el5 set to be updated --> Running transaction check ---> Package cpp.i386 0:4.1.2-50.el5 set to be updated ---> Package elfutils-libs.i386 0:0.137-3.el5 set to be updated ---> Package glibc-devel.i386 0:2.5-58 set to be updated --> Processing Dependency: glibc-headers = 2.5-58 for package: glibc-devel --> Processing Dependency: glibc = 2.5-58 for package: glibc-devel --> Processing Dependency: glibc-headers for package: glibc-devel ---> Package krb5-devel.i386 0:1.6.1-55.el5_6.1 set to be updated --> Processing Dependency: krb5-libs = 1.6.1-55.el5_6.1 for package: krb5-devel --> Processing Dependency: libselinux-devel for package: krb5-devel --> Processing Dependency: e2fsprogs-devel for package: krb5-devel --> Processing Dependency: keyutils-libs-devel for package: krb5-devel ---> Package libgcc.i386 0:4.1.2-50.el5 set to be updated ---> Package libgomp.i386 0:4.4.4-13.el5 set to be updated ---> Package openssl.i686 0:0.9.8e-12.el5_5.7 set to be updated ---> Package perl-DBI.i386 0:1.52-2.el5 set to be updated ---> Package rpm-python.i386 0:4.4.2.3-22.el5 set to be updated ---> Package zlib-devel.i386 0:1.2.3-3 set to be updated --> Running transaction check ---> Package e2fsprogs-devel.i386 0:1.39-23.el5_5.1 set to be updated --> Processing Dependency: e2fsprogs-libs = 1.39-23.el5_5.1 for package: e2fsprogs-devel --> Processing Dependency: glibc = 2.5-49 for package: nscd ---> Package glibc.i686 0:2.5-58 set to be updated --> Processing Dependency: glibc-common = 2.5-58 for package: glibc ---> Package glibc-headers.i386 0:2.5-58 set to be updated --> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers --> Processing Dependency: kernel-headers for package: glibc-headers ---> Package keyutils-libs-devel.i386 0:1.2-1.el5 set to be updated --> Processing Dependency: krb5-libs = 1.6.1-36.el5_4.1 for package: krb5-workstation ---> Package krb5-libs.i386 0:1.6.1-55.el5_6.1 set to be updated ---> Package libselinux-devel.i386 0:1.33.4-5.7.el5 set to be updated --> Processing Dependency: libselinux = 1.33.4-5.7.el5 for package: libselinux-devel --> Processing Dependency: libsepol-devel >= 1.15.2-1 for package: libselinux-devel --> Running transaction check --> Processing Dependency: e2fsprogs-libs = 1.39-23.el5 for package: e2fsprogs ---> Package e2fsprogs-libs.i386 0:1.39-23.el5_5.1 set to be updated ---> Package glibc-common.i386 0:2.5-58 set to be updated ---> Package kernel-headers.i386 0:2.6.18-238.5.1.el5 set to be updated ---> Package krb5-workstation.i386 0:1.6.1-55.el5_6.1 set to be updated --> Processing Dependency: libselinux = 1.33.4-5.5.el5 for package: libselinux-utils --> Processing Dependency: libselinux = 1.33.4-5.5.el5 for package: libselinux-python ---> Package libselinux.i386 0:1.33.4-5.7.el5 set to be updated ---> Package libsepol-devel.i386 0:1.15.2-3.el5 set to be updated ---> Package nscd.i386 0:2.5-58 set to be updated --> Running transaction check ---> Package e2fsprogs.i386 0:1.39-23.el5_5.1 set to be updated ---> Package libselinux-python.i386 0:1.33.4-5.7.el5 set to be updated ---> Package libselinux-utils.i386 0:1.33.4-5.7.el5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: gcc-c++ i386 4.1.2-50.el5 base 3.4 M mysql-devel i386 5.0.77-4.el5_5.5 updates 2.4 M python26-devel i386 2.6.5-6.el5 epel 169 k rpm-build i386 4.4.2.3-22.el5 base 302 k Installing for dependencies: cpp i386 4.1.2-50.el5 base 2.7 M e2fsprogs-devel i386 1.39-23.el5_5.1 base 569 k elfutils i386 0.137-3.el5 base 228 k elfutils-libs i386 0.137-3.el5 base 193 k gcc i386 4.1.2-50.el5 base 5.2 M glibc-devel i386 2.5-58 base 2.0 M glibc-headers i386 2.5-58 base 603 k kernel-headers i386 2.6.18-238.5.1.el5 updates 1.1 M keyutils-libs-devel i386 1.2-1.el5 base 27 k krb5-devel i386 1.6.1-55.el5_6.1 updates 1.9 M libgomp i386 4.4.4-13.el5 base 72 k libselinux-devel i386 1.33.4-5.7.el5 base 144 k libsepol-devel i386 1.15.2-3.el5 base 187 k libstdc++-devel i386 4.1.2-50.el5 base 2.8 M mysql i386 5.0.77-4.el5_5.5 updates 4.8 M openssl-devel i386 0.9.8e-12.el5_5.7 base 1.9 M perl-DBI i386 1.52-2.el5 base 600 k zlib-devel i386 1.2.3-3 base 101 k Updating for dependencies: e2fsprogs i386 1.39-23.el5_5.1 base 977 k e2fsprogs-libs i386 1.39-23.el5_5.1 base 118 k glibc i686 2.5-58 base 5.3 M glibc-common i386 2.5-58 base 16 M krb5-libs i386 1.6.1-55.el5_6.1 updates 666 k krb5-workstation i386 1.6.1-55.el5_6.1 updates 885 k libgcc i386 4.1.2-50.el5 base 96 k libselinux i386 1.33.4-5.7.el5 base 77 k libselinux-python i386 1.33.4-5.7.el5 base 73 k libselinux-utils i386 1.33.4-5.7.el5 base 55 k libstdc++ i386 4.1.2-50.el5 base 362 k nscd i386 2.5-58 base 166 k openssl i686 0.9.8e-12.el5_5.7 base 1.4 M popt i386 1.10.2.3-22.el5 base 75 k rpm i386 4.4.2.3-22.el5 base 1.2 M rpm-libs i386 4.4.2.3-22.el5 base 928 k rpm-python i386 4.4.2.3-22.el5 base 60 k Transaction Summary ================================================================================ Install 22 Package(s) Upgrade 17 Package(s) Total download size: 60 M Is this ok [y/N]: y Downloading Packages: (1/39): keyutils-libs-devel-1.2-1.el5.i386.rpm | 27 kB 00:00 (2/39): libselinux-utils-1.33.4-5.7.el5.i386.rpm | 55 kB 00:00 (3/39): rpm-python-4.4.2.3-22.el5.i386.rpm | 60 kB 00:00 (4/39): libgomp-4.4.4-13.el5.i386.rpm | 72 kB 00:00 (5/39): libselinux-python-1.33.4-5.7.el5.i386.rpm | 73 kB 00:00 (6/39): popt-1.10.2.3-22.el5.i386.rpm | 75 kB 00:00 (7/39): libselinux-1.33.4-5.7.el5.i386.rpm | 77 kB 00:00 (8/39): libgcc-4.1.2-50.el5.i386.rpm | 96 kB 00:00 (9/39): zlib-devel-1.2.3-3.i386.rpm | 101 kB 00:00 (10/39): e2fsprogs-libs-1.39-23.el5_5.1.i386.rpm | 118 kB 00:00 (11/39): libselinux-devel-1.33.4-5.7.el5.i386.rpm | 144 kB 00:00 (12/39): nscd-2.5-58.i386.rpm | 166 kB 00:00 (13/39): python26-devel-2.6.5-6.el5.i386.rpm | 169 kB 00:01 (14/39): libsepol-devel-1.15.2-3.el5.i386.rpm | 187 kB 00:00 (15/39): elfutils-libs-0.137-3.el5.i386.rpm | 193 kB 00:00 (16/39): elfutils-0.137-3.el5.i386.rpm | 228 kB 00:00 (17/39): rpm-build-4.4.2.3-22.el5.i386.rpm | 302 kB 00:00 (18/39): libstdc++-4.1.2-50.el5.i386.rpm | 362 kB 00:00 (19/39): e2fsprogs-devel-1.39-23.el5_5.1.i386.rpm | 569 kB 00:00 (20/39): perl-DBI-1.52-2.el5.i386.rpm | 600 kB 00:00 (21/39): glibc-headers-2.5-58.i386.rpm | 603 kB 00:01 (22/39): krb5-libs-1.6.1-55.el5_6.1.i386.rpm | 666 kB 00:04 (23/39): krb5-workstation-1.6.1-55.el5_6.1.i386.rpm | 885 kB 00:01 (24/39): rpm-libs-4.4.2.3-22.el5.i386.rpm | 928 kB 00:00 (25/39): e2fsprogs-1.39-23.el5_5.1.i386.rpm | 977 kB 00:00 (26/39): kernel-headers-2.6.18-238.5.1.el5.i386.rpm | 1.1 MB 00:00 (27/39): rpm-4.4.2.3-22.el5.i386.rpm | 1.2 MB 00:00 (28/39): openssl-0.9.8e-12.el5_5.7.i686.rpm | 1.4 MB 00:01 (29/39): krb5-devel-1.6.1-55.el5_6.1.i386.rpm | 1.9 MB 00:06 (30/39): openssl-devel-0.9.8e-12.el5_5.7.i386.rpm | 1.9 MB 00:01 (31/39): glibc-devel-2.5-58.i386.rpm | 2.0 MB 00:01 (32/39): mysql-devel-5.0.77-4.el5_5.5.i386.rpm | 2.4 MB 00:02 (33/39): cpp-4.1.2-50.el5.i386.rpm | 2.7 MB 00:05 (34/39): libstdc++-devel-4.1.2-50.el5.i386.rpm | 2.8 MB 00:03 (35/39): gcc-c++-4.1.2-50.el5.i386.rpm | 3.4 MB 00:07 (36/39): mysql-5.0.77-4.el5_5.5.i386.rpm | 4.8 MB 00:03 (37/39): gcc-4.1.2-50.el5.i386.rpm | 5.2 MB 00:09 (38/39): glibc-2.5-58.i686.rpm | 5.3 MB 00:03 (39/39): glibc-common-2.5-58.i386.rpm | 16 MB 00:25 -------------------------------------------------------------------------------- Total 642 kB/s | 60 MB 01:35 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Updating : glibc-common 1/56 Installing : kernel-headers 2/56 Installing : libsepol-devel 3/56 Installing : zlib-devel 4/56 Installing : keyutils-libs-devel 5/56 Updating : libgcc 6/56 Updating : glibc 7/56 Updating : libselinux 8/56 Updating : e2fsprogs-libs 9/56 Updating : popt 10/56 Updating : krb5-libs 11/56 Updating : libstdc++ 12/56 Updating : openssl 13/56 Installing : libgomp 14/56 Installing : perl-DBI 15/56 Installing : mysql 16/56 Installing : cpp 17/56 Installing : elfutils-libs 18/56 Installing : elfutils 19/56 Updating : krb5-workstation 20/56 Updating : e2fsprogs 21/56 Updating : libselinux-python 22/56 Updating : libselinux-utils 23/56 Updating : nscd 24/56 Installing : libstdc++-devel 25/56 Installing : e2fsprogs-devel 26/56 Installing : libselinux-devel 27/56 Installing : glibc-headers 28/56 Installing : glibc-devel 29/56 Installing : python26-devel 30/56 Installing : gcc 31/56 Installing : krb5-devel 32/56 Installing : gcc-c++ 33/56 Installing : openssl-devel 34/56 Installing : mysql-devel 35/56 Updating : rpm-libs 36/56 Updating : rpm 37/56 Installing : rpm-build 38/56 Updating : rpm-python 39/56 Cleanup : e2fsprogs-libs 40/56 Cleanup : glibc-common 41/56 Cleanup : libselinux-python 42/56 Cleanup : krb5-workstation 43/56 Cleanup : rpm 44/56 Cleanup : rpm-python 45/56 Cleanup : libstdc++ 46/56 Cleanup : libselinux-utils 47/56 Cleanup : popt 48/56 Cleanup : nscd 49/56 Cleanup : glibc 50/56 Cleanup : e2fsprogs 51/56 Cleanup : libgcc 52/56 Cleanup : krb5-libs 53/56 Cleanup : libselinux 54/56 Cleanup : rpm-libs 55/56 Cleanup : openssl 56/56 Installed: gcc-c++.i386 0:4.1.2-50.el5 mysql-devel.i386 0:5.0.77-4.el5_5.5 python26-devel.i386 0:2.6.5-6.el5 rpm-build.i386 0:4.4.2.3-22.el5 Dependency Installed: cpp.i386 0:4.1.2-50.el5 e2fsprogs-devel.i386 0:1.39-23.el5_5.1 elfutils.i386 0:0.137-3.el5 elfutils-libs.i386 0:0.137-3.el5 gcc.i386 0:4.1.2-50.el5 glibc-devel.i386 0:2.5-58 glibc-headers.i386 0:2.5-58 kernel-headers.i386 0:2.6.18-238.5.1.el5 keyutils-libs-devel.i386 0:1.2-1.el5 krb5-devel.i386 0:1.6.1-55.el5_6.1 libgomp.i386 0:4.4.4-13.el5 libselinux-devel.i386 0:1.33.4-5.7.el5 libsepol-devel.i386 0:1.15.2-3.el5 libstdc++-devel.i386 0:4.1.2-50.el5 mysql.i386 0:5.0.77-4.el5_5.5 openssl-devel.i386 0:0.9.8e-12.el5_5.7 perl-DBI.i386 0:1.52-2.el5 zlib-devel.i386 0:1.2.3-3 Dependency Updated: e2fsprogs.i386 0:1.39-23.el5_5.1 e2fsprogs-libs.i386 0:1.39-23.el5_5.1 glibc.i686 0:2.5-58 glibc-common.i386 0:2.5-58 krb5-libs.i386 0:1.6.1-55.el5_6.1 krb5-workstation.i386 0:1.6.1-55.el5_6.1 libgcc.i386 0:4.1.2-50.el5 libselinux.i386 0:1.33.4-5.7.el5 libselinux-python.i386 0:1.33.4-5.7.el5 libselinux-utils.i386 0:1.33.4-5.7.el5 libstdc++.i386 0:4.1.2-50.el5 nscd.i386 0:2.5-58 openssl.i686 0:0.9.8e-12.el5_5.7 popt.i386 0:1.10.2.3-22.el5 rpm.i386 0:4.4.2.3-22.el5 rpm-libs.i386 0:4.4.2.3-22.el5 rpm-python.i386 0:4.4.2.3-22.el5 Complete!
Isso foi grande, mas o yum fez todo o trabalho sujo por você. Agora precisamos do código do driver MySQL do Python. Você encontra esse cara no SourceForge (pense em "GitHub dos anos 90").
[root@centos ~]# wget http://ufpr.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/ MySQL-python-1.2.3.tar.gz --2011-04-08 20:06:12-- http://ufpr.dl.sourceforge.net/project/mysql-python/mysql-python/ 1.2.3/MySQL-python-1.2.3.tar.gz Resolving ufpr.dl.sourceforge.net... 200.236.31.2 Connecting to ufpr.dl.sourceforge.net|200.236.31.2|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 70305 (69K) [application/x-gzip] Saving to: `MySQL-python-1.2.3.tar.gz' 100%[======================================>] 70,305 328K/s in 0.2s 2011-04-08 20:06:13 (328 KB/s) - `MySQL-python-1.2.3.tar.gz' saved [70305/70305] [root@centos ~]# tar zxvf MySQL-python-1.2.3.tar.gz MySQL-python-1.2.3/ MySQL-python-1.2.3/setup.py MySQL-python-1.2.3/doc/ MySQL-python-1.2.3/doc/FAQ.txt MySQL-python-1.2.3/doc/.cvsignore MySQL-python-1.2.3/doc/MySQLdb.txt MySQL-python-1.2.3/MANIFEST.in MySQL-python-1.2.3/_mysql.c MySQL-python-1.2.3/_mysql_exceptions.py MySQL-python-1.2.3/ez_setup.py MySQL-python-1.2.3/setup.cfg
zzz
MySQL-python-1.2.3/MySQL_python.egg-info/SOURCES.txt MySQL-python-1.2.3/MySQL_python.egg-info/PKG-INFO MySQL-python-1.2.3/MySQL_python.egg-info/top_level.txt MySQL-python-1.2.3/setup_common.py MySQL-python-1.2.3/README
Agora a dança da instalação
[root@centos ~]# cd MySQL-python-1.2.3 [root@centos MySQL-python-1.2.3]# python2.6 setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info/PKG-INFO writing top-level names to MySQL_python.egg-info/top_level.txt writing dependency_links to MySQL_python.egg-info/dependency_links.txt reading manifest file 'MySQL_python.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching 'MANIFEST' warning: no files found matching 'ChangeLog' warning: no files found matching 'GPL' writing manifest file 'MySQL_python.egg-info/SOURCES.txt' installing library code to build/bdist.linux-i686/egg running install_lib running build_py creating build creating build/lib.linux-i686-2.6 copying _mysql_exceptions.py -> build/lib.linux-i686-2.6 creating build/lib.linux-i686-2.6/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb creating build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.linux-i686-2.6 gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv gcc -pthread -shared build/temp.linux-i686-2.6/_mysql.o -L/usr/lib/mysql -L/usr/lib -L/usr/lib -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-i686-2.6/_mysql.so creating build/bdist.linux-i686 creating build/bdist.linux-i686/egg creating build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.6/MySQLdb/times.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.6/MySQLdb/connections.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.6/MySQLdb/cursors.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.6/MySQLdb/converters.py -> build/bdist.linux-i686/egg/MySQLdb creating build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/FLAG.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/CLIENT.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/CR.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/__init__.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/REFRESH.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/constants/ER.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.6/MySQLdb/release.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.6/MySQLdb/__init__.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.6/_mysql_exceptions.py -> build/bdist.linux-i686/egg copying build/lib.linux-i686-2.6/_mysql.so -> build/bdist.linux-i686/egg byte-compiling build/bdist.linux-i686/egg/MySQLdb/times.py to times.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/connections.py to connections.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/cursors.py to cursors.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/converters.py to converters.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/FLAG.py to FLAG.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/CR.py to CR.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/__init__.py to __init__.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/ER.py to ER.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/release.py to release.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/__init__.py to __init__.pyc byte-compiling build/bdist.linux-i686/egg/_mysql_exceptions.py to _mysql_exceptions.pyc creating stub loader for _mysql.so byte-compiling build/bdist.linux-i686/egg/_mysql.py to _mysql.pyc creating build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-i686/egg/EGG-INFO writing build/bdist.linux-i686/egg/EGG-INFO/native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist/MySQL_python-1.2.3-py2.6-linux-i686.egg' and adding 'build/bdist.linux-i686/egg' to it removing 'build/bdist.linux-i686/egg' (and everything under it) Processing MySQL_python-1.2.3-py2.6-linux-i686.egg creating /usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg Extracting MySQL_python-1.2.3-py2.6-linux-i686.egg to /usr/lib/python2.6/site-packages Adding MySQL-python 1.2.3 to easy-install.pth file Installed /usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg Processing dependencies for MySQL-python==1.2.3 Finished processing dependencies for MySQL-python==1.2.3
Agora é testar.
[root@centos MySQL-python-1.2.3]# python -c "import MySQLdb" Traceback (most recent call last): File "<string>", line 1, in ? File "MySQLdb/__init__.py", line 19, in ? import _mysql ImportError: No module named _mysql
Oops! Esse foi o Python 2.4. Não tínhamos instalado o driver para ele. Tudo bem, porque não vamos usá-lo. Se algum dia o CentOS quiser instalar um driver de MySQL para ele, ele pode. Nós não vamos.
[root@centos MySQL-python-1.2.3]# python2.6 -c "import MySQLdb" [root@centos MySQL-python-1.2.3]#
Unixes adotam a filosofia de no news is good news. Nesse caso, nada aconteceu. Isso inclui "nada de errado", o que só pode ser um bom sinal. Agora vamos instalar o Django do jeito mais simples que existe - usando o pip:
[root@centos ~]# pip-2.6 install django Downloading/unpacking django Downloading Django-1.3.tar.gz (6.5Mb): 6.5Mb downloaded Running setup.py egg_info for package django Installing collected packages: django Running setup.py install for django changing mode of build/scripts-2.6/django-admin.py from 644 to 755 changing mode of /usr/bin/django-admin.py to 755 Successfully installed django Cleaning up...
E testá-lo:
[root@centos ~]# python2.6 Python 2.6.5 (r265:79063, Feb 28 2011, 21:55:56) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.get_version() '1.3' >>>
E ainda é a versão mais nova!
Os próximos passos são instalar um MySQL, um Apache, um mod_wsgi e montar uma aplicação besta para ter certeza de que todas as peças estão nos seus devidos lugares. Isso fica para um próximo artigo.