您的位置:首页 > 编程语言 > Python开发

install python 3.2, django and eclipse pydev plugin in mac for python devolopment

2012-03-07 22:39 681 查看
Step 1. install eclipse 3.7 or later

Step 2. install python 3.2 (ref link: http://www.youtube.com/watch?v=MEmEJCLLI2k )

注意:我安装了python3.2后,在"terminal"里输入命令 "python --version",出现的版本是v2.7,如果你要在terminal里使用python 3.2,需要使用命令"python3.2"

Step 3. install django (ref link: https://docs.djangoproject.com/en/dev/intro/install/ )

注意:官方文档写清楚了django v1.4只支持python2.6~2.7,不支持python3.因此当前使用django v1.4.1 + python 2.7

* download django tar.gz at https://www.djangoproject.com/
* > tar xzvf Django-xxx.tar.gz

* > cd Django-xxx

若要安装到python 2.7里,则执行 (将会把django安装到/Library/Python/2.7/site-packages/目录下

* > sudo python setup.py install

* 安装完之后 执行

> python

>>>import django

>>>print(django.get_version())

将显示django的version

如何删除django?

只需要删除“site-packages"目录下(在mac os是/Library/Python/2.7/site-packages/目录下) django目录即可!

注意:在upgrade django之前应该先删除旧版本

Step 4. install pydev plugin in eclipse: select menu "help–>eclipse marketplace", 搜索"Pydev"之后安装即可

Step 5. how to set pydev's python interpreter in "preference" (similar with setting jdk path) and create a "hello world" python project (ref link: http://www.youtube.com/watch?v=gCapULV-tPE )
注意,在设置python interpreter时:

* click "Auto Config"来添加python interpreter



* 在”select the folders to be added to the system pythonpath“ list里,必须钩上 “site-packages"目录,否则无法create django project

Step 6. how to create a django project and run it? (转载自:http://www.stevenwang.name/eclipse-django-begin-177001.html)

新建一个"Pydev Django Project","interpreter"选之前在pydev中配置的名称,去掉"Create default 'src' folder and add it to the pythonpath?"前面的勾,"Referenced projects"如果没有则不需要勾选,如果程序没有数据库支持则去掉"Database Engine"中的内容,至此,新建"helloworld"项目完成。

项目将自动包含四个文件:__init__.py, manage.py, settings.py, urls.py

在helloworld包中新建一个helloworld.py文件,内容如下:

from django.http import HttpResponse

def index(request):
return HttpResponse('Hello World!')
将urls.py文件的内容修改为:

from django.conf.urls.defaults import patterns

urlpatterns = patterns('',
(r'^$', 'helloworld.helloworld.index')
)


以上程序的目的是,把对Web服务器根目录的请求路由到之前新建的helloworld.py文件中的index函数来处理。

右键点helloworld项目,【Run As】—【Pydev:Django】,待Web服务启动后,在浏览器中输入http://127.0.0.1:8000/ ,若请求返回"Hello World!",则说明第一个Django程序已成功运行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: