1.下载
Django 下载地址:https://www.djangoproject.com/download/
2.解压
下载 Django 压缩包,解压并和Python安装目录放在同一个根目录,进入 Django 目录,执行python setup.py install,然后开始安装,Django将要被安装到Python的Lib下site-packages。
3.环境变量配置
然后是配置环境变量,将这几个目录添加到系统环境变量中:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\Django-2.2.7-py3.7.egg\django
C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\Scripts。
4.命令确认
检查是否安装成功
5.可能错误及解决办法
django 创建项目时遇到的一些问题:
创建mysite项目:
django-admin startproject mysite
报错信息:
pkg_resources.DistributionNotFound: The ‘sqlparse’ distribution was not found and is required by Django
原因是缺少sqlparse 模块
解决方法: pip3 install sqlparse --index https://pypi.tuna.tsinghua.edu.cn/simple/
PS: 如果以上镜像不可用,试试下面
Python官方 https://pypi.python.org/simple
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
douban http://pypi.douban.com/simple
v2ex http://pypi.v2ex.com/simple
中国科学院 http://pypi.mirrors.opencas.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
报错信息:
django 2.2.4 requires pytz, which is not installed.
提示django2.2.4 需要提供pytz 模块
解决方法:pip3 install pytz --index https://pypi.tuna.tsinghua.edu.cn/simple/
6.配置网络请求
安装完这两个模块后再执行项目创建命令没有再出现报错