Mac中安装Python+Django+MySQL完整步骤
来源:互联网 发布:淘宝拍立得 编辑:程序博客网 时间:2024/06/03 01:42
1 Mac系统默认自带Python,查看版本:命令行输入:pythonPython 2.7.6 (default, Sep 9 2014, 15:04:36)版本号为2.7.6所以不用安装了2 安装Django,最新的版本1.7(1)首先使用easy_install安装pip(easy_install是Python的包管理工具,类似Ruby下的gem,pip是升级版的easy_install), sudo easy_install pip(2)安装成功后,安装Django, pip install Django==1.7 ---->我用的是1.9的版本(3)查看安装路径:默认为/usr/bin,如果看到django-admin.py说明安装成功,django-admin.py是Django的管理工具,用来生成项目和应用3 连接mysql(1)安装mysql for mac,直接从官网上下载dmg文件安装即可,需要64位版本 这一步我做了好久,没有找到mac版的Mysql安装文件,我下载的5.6的tar.gz文件,详细的安装步骤看我的 http://blog.csdn.net/u014057054/article/details/52070390这篇文章(2)安装mysql python驱动, sudo easy_install mysql-python这一步也是不不惊心,需要command_line_tools的xcode才能安装,我很久都没有登录苹果的AppStore了,密码都忘记了,给一个下载之前 苹果文件的下载地址(https://developer.apple.com/download/more/ 需要什么的可以去里面找),找到安装就OK了。4 创建第一个项目(1)创建项目:django-admin.py startproject demoproject(2)创建应用:cd demoprojectpython manage.py startapp demoapp创建成功(3)修改settting.py,将demoapp加入到INSTALLED_APPSINSTALLED_APPS = ('django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','demoapp')(4)修改settting.py,将默认的sqlite数据库换成mysqlDATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','NAME': 'djangodb','USER': 'root','PASSWORD': 'root','HOST': '127.0.0.1','PORT': '3306',}}(5)在demoproject下输入:python manage.py dbshell,如果能正常进入mysql命令行,则说明连接成功 提示一下,这个要提前在Mysql中创建djangodb数据库。Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 270Server version: 5.5.38 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>sudo python manage.py dbshell一直报错,找了一晚上 File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/znt/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/znt/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so Reason: image not found就是我手动安装的Mysql的库没有在系统的类库目中找到,python一直提示错误,执行下面的语句就问题解决了 sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
5 启动应用(1)同步数据库:执行python manage.py syncdb,第一次启动需要创建superuser,用来管理django后台
这一步是没有必要的,django1.7.4之后就没有了这个syncdb命令了。。。。,我用的是django1.9Operations to perform:Apply all migrations: admin, contenttypes, auth, sessionsRunning migrations:Applying contenttypes.0001_initial... OKApplying auth.0001_initial... OKApplying admin.0001_initial... OKApplying sessions.0001_initial... OKYou have installed Django's auth system, and don't have any superusers defined.Would you like to create one now? (yes/no): yesUsername (leave blank to use 'thierry'): thierryEmail address: thierry.xing@gmail.comPassword:Password (again):Superuser created successfully.(2)启动服务:python manage.py runserver:Performing system checks...System check identified no issues (0 silenced).December 03, 2014 - 08:36:46Django version 1.7, using settings 'djproject.settings'Starting development server at http://127.0.0.1:8000/Quit the server with CONTROL-C.启动成功,在浏览器输入http://127.0.0.1:8000/打开应用在浏览器输入http://127.0.0.1:8000/admin进入后台管理应用
0 0
- Mac中安装Python+Django+MySQL完整步骤
- mac中安装Python+Django+MySQL
- MAC下安装MySQL+Django详细步骤
- mac系统下安装python Django的步骤 实测有效
- Python和Django安装步骤
- Python和Django安装步骤
- Python和Django安装步骤
- CentOS 6.5 中 Yum 方法安装 MySQL 5.7 完整步骤
- Mac下安装mysql5.7 完整步骤
- 在 Mac 中安装 MySQLdb (Python mysql )
- 在 Mac 中安装 MySQLdb (Python mysql )
- 在 Mac 中安装 MySQLdb (Python mysql )
- 在 Mac 中安装 MySQLdb (Python mysql )
- mac osx 安装mysql步骤
- python中django安装
- Mac下安装mysql5.7 完整步骤以及 Mac平台重新设置MySQL的root密码等问题汇总
- Mac下安装mysql5.7 完整步骤以及 Mac平台重新设置MySQL的root密码等问题汇总
- mac 安装MySQL-python
- JAVA——垃圾收集器与内存分配策略
- 笛卡尔&小雷:科学发展有规律,研究科学有方法
- 5-22 龟兔赛跑 (20分)
- CentOS 基本信息查询命令
- 数据结构上机测试2-1:单链表操作A
- Mac中安装Python+Django+MySQL完整步骤
- 计算一个N个选项中和为X的所有组合数
- Android 开发之第三方库之 EventBus
- 使用随机梯度算法对高斯核模型进行最小二乘法的MATLAB程序
- 5-23 币值转换 (20分)
- 伪类和伪元素
- hdu 1180 诡异的楼梯
- Linux下卸载mysql
- 回调函数