django 在centos5.5上的安裝
周海漢
2012.11.6
[[email protected] ~]$ cat /etc/redhat-release CentOS release 5.5 (Final)
下載django
[[email protected] ~]$ wget https://www.djangoproject.com/download/1.4.2/tarball/
[[email protected] Django-1.4.2]$ python setup.py build [[email protected] Django-1.4.2]$ sudo python setup.py install
安裝pip
[[email protected] pip-1.2.1]$ python setup.py build
Traceback (most recent call last):
File “setup.py”, line 5, in
安裝setuptools
http://pypi.python.org/pypi/setuptools
[[email protected] python]$ wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea
[
[[email protected] python]$ sudo bash setuptools-0.6c11-py2.7.egg setuptools-0.6c11-py2.7.egg: line 3: exec: python2.7: not found [[email protected]
在root下visudo,修改/etc/sudoers,將Defaults env_reset改成Defaults !env_reset [[email protected] python]$ sudo bash setuptools-0.6c11-py2.7.egg
再安裝pip [[email protected] python]$ sudo curl -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
error: could not create ‘/usr/local/lib/python2.7/site-packages/pip’: Permission denied
[[email protected] ~]# curl -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python Downloading pip-1.2.1.tar.gz 安裝pip完畢
安裝 MySQLdb 地址:http://www.djangoproject.com/r/python-mysql/
[[email protected] t3]$ sudo pip install MySQLdb No distributions at all found for MySQLdb http://sourceforge.net/projects/mysql-python/ [[email protected] python]$ wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download [[email protected] MySQL-python-1.2.3]$ python setup.py build _mysql.c:36:23: error: my_config.h: No such file or directory … [[email protected] ~]$ sudo yum install MySQL-python.x86_64 MySQL-python-1.2.3-0.1.c1.el5.x86_64 from base has depsolving problems Error: Missing Dependency: libmysqlclient_r.so.15()(64bit)
找不到libmysqlclient_r.so.15,需安裝它。 [[email protected] ~]$ wget ftp://rpmfind.net/linux/centos/5.8/updates/x86_64/RPMS/mysql-5.0.95-1.el5_7.1.x86_64.rpm [[email protected] ~]$ sudo rpm -ivh mysql-5.0.95-1.el5_7.1.x86_64.rpm error: Failed dependencies: perl(DBI) is needed by mysql-5.0.95-1.el5_7.1.x86_64
安裝perl-DBI和mysql [[email protected] ~]$ sudo yum install perl-DBI.x86_64
[[email protected] ~]$ sudo rpm -ivh mysql-5.0.95-1.el5_7.1.x86_64.rpm Preparing… ########################################### [100%] package mysql-5.5.15-1.el5.remi.x86_64 (which is newer than mysql-5.0.95-1.el5_7.1.x86_64) is already installed file /etc/my.cnf from install of mysql-5.0.95-1.el5_7.1.x86_64 conflicts with file from package mysql-libs-5.5.15-1.el5.remi.x86_64 …
mysql版本有衝突,已安裝版本較新,需解除安裝降級
[[email protected] ~]$ sudo yum remove mysql.x86_64 [[email protected] ~]$ sudo yum remove mysql-libs* [[email protected] ~]$ sudo yum install mysql-5.0.95-1.el5_7.1.x86_64 Installed: mysql.x86_64 0:5.0.95-1.el5_7.1
Complete! [[email protected] ~]$ sudo yum install MySQL-python.x86_64 Installed: MySQL-python.x86_64 0:1.2.3-0.1.c1.el5
Complete!
對ubuntu,用sudo apt-get install python-mysqldb 解決django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb錯誤。
[[email protected] lib]$ sudo pip install mysql-python _mysql.c:44:23: error: my_config.h: No such file or directory
_mysql.c:46:19: error: mysql.h: No such file or directory … 安裝mysql-server [[email protected] lib]$ sudo yum instlall mysql-devel.x86_64 [[email protected] lib]$ sudo yum install mysql-server.x86_64 [[email protected] lib]$ sudo pip install mysql-python Successfully installed mysql-python Cleaning up…
建立專案,django hello
[[email protected] www]$ django-admin.py startproject t3 [[email protected] www]$ find t3 t3 t3/t3 t3/t3/init.py t3/t3/settings.py t3/t3/wsgi.py t3/t3/urls.py t3/manage.py [[email protected] t3]$ cat t3/settings.py
DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.mysql’ ‘NAME’: ‘t3’, # Or path to database file if using sqlite3. ‘USER’: ‘root’, # Not used with sqlite3. ‘PASSWORD’: ‘’, # Not used with sqlite3. ‘HOST’: ‘hadoop48’, # Set to empty string for localhost. Not used with sqlite3. ‘PORT’: ‘’, # Set to empty string for default. Not used with sqlite3. } } … TIME_ZONE = ‘Asia/Hong_Kong’ … [[email protected] t3]$ cat t3/views.py #/usr/bin/env python
– coding:utf8–
from django.http import HttpResponse
def hello(request):
return HttpResponse(“hello,world”);
[[email protected] t3]$ cat t3/urls.py … from t3.views import hello urlpatterns = patterns(‘’,
Examples:
(‘^hello/$’, hello), … [[email protected] t3]$ ./manage.py runserver 192.168.10.47:8000 如果MySQLdb和mysql程式沒裝好,會出如下錯誤: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb 所以需要先安裝mysql和MySQLdb python模組
[[email protected] t3]$ ./manage.py runserver Validating models…
0 errors found Django version 1.4.2, using settings ‘t3.settings’ Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. 但這個不能在其他機器訪問 [[email protected] t3]$ ./manage.py runserver 192.168.10.47:8000 Validating models…
0 errors found Django version 1.4.2, using settings ‘t3.settings’ Development server is running at http://192.168.10.47:8000/ Quit the server with CONTROL-C.
訪問
此時用瀏覽器訪問 http://hadoop47:8000/hello 返回: hello,world
參考:
如非註明轉載, 均為原創. 本站遵循知識共享CC協議,轉載請註明來源