Django 环境搭建(CentOS65 + Django1.7 + mySQL5.1)

入职第二天,搭Django 环境,留个记录

更新系统

yum -y update


安装EPEL

 wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm


rpm -ivh epel-release-6-8.noarch.rpm


yum repolist 检查


将系统自带的python2.6.6 更新到2.7.8

yum install -y gcc

wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz 

tar -zxvf  Python-2.7.8.tgz 

./configure

make

make的最后提示以下模块没有build,

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _curses            _curses_panel   
_sqlite3           _ssl               _tkinter        
bsddb185           bz2                dbm             
dl                 gdbm               imageop         
readline           sunaudiodev        zlib       

安装相关devel包

_sqlite3        sqlite-devel.x86_64 
_ssl            openssl-devel.x86_64
_curses         ncurses-devel.x86_64
_curses_panel   ncurses-devel.x86_64
bz2             bzip2-devel.x86_64 
gdbm            gdbm-devel.x86_64
readline        readline-devel.x86_64

再次执行make

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             bsddb185           dl              
imageop            sunaudiodev      
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


还有几个模块,如下原因未安装

dl            Call C functions in shared objects.Python2.6开始,已经弃用。
imageop       Manipulate raw image data。已经弃用。
sunaudiodev   Access to Sun audio hardware。这个是针对Sun平台的,CentOS下可以忽略
bsddb185      老的bsddb模块,可忽略。
_bsddb        Interface to Berkeley DB library。Berkeley数据库的接口, 
              可从Oracle网站下载http://www.oracle.com/technology/products/berkeley-db/index.html

最后, 使用make install  完成安装

如果configure 时不使用 --prefix, 比如  ./configure --prefix=/usr/hao/python2.7, 默认的安装路径是/usr/local/python2.7


修改路径,使用新版本的python

mv /usr/bin/python /usr/bin/python.old
ln -s /usr/local/bin/python2.7 /usr/bin/python

yum 使用python, 更新python2.7.8 后会报错,修改如下

vi  /usr/bin/yum, 将 #!/usr/bin/python 修改为 #!/usr/bin/python.old


安装virtualenv


安装setuptools

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-6.1.tar.gz
tar -zxvf setuptools-6.1.tar.gz 
python setup.py install 

安装pip
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz
tar -zxvf  pip-1.5.6.tar.gz
python setup.py install


pip install virtualenv virtualenvwrapper

修改profile  , vim ~/.bash_profile , 增加以下内容

export WORKON_HOME=$HOME/Envs
export PROJECT_HOME=/
source /usr/local/bin/virtualenvwrapper.sh

创建新环境

mkvirtualenv <envname>


列出环境

workon 或 lsvirtualenv


切换环境

workon  <envname>


离开环境

deactivate


删除虚拟环境

rmvirtualenv <envname>


创建环境mydj

mkproject mydj

在WORKON_HOME 中创建一个virtualenv, 同时在PROJECT_HOME 中创建同名目录


setvirtualenvproject 设置项目路径

cdproject 切换至项目路径



安装MySQL


查看是否有mySQL安装

[root@cos65 ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-3.el6_5.x86_64

卸载软件包

yum erase mysql-libs-5.1.73-3.el6_5.x86_64


通过yum方式安装

yum list | grep -i mysql

yum install -y mysql-server mysql mysql-devel


启动服务

mysql: 未被识别的服务
[root@cos65 ~]# service mysqld start
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cos65 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [确定]
正在启动 mysqld:                                          [确定]


重置mysql默认密码

/usr/bin/mysqladmin -u root password 'mysql'

连接mysql

mysql -pmysql (-p和密码没有空格)

[root@cos65 ~]# mysql -pmysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)



安装Django 

进入virutal 环境


wokon mydj

pip install Django

进入pyhon

>>> import django
>>> django.VERSION
(1, 7, 0, 'final', 0)


安装mysql driver

pip install MySQL-python

进入python , import MySQLdb验证


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值