系统相关
首页 > 系统相关> > python学习笔记--开发与调试环境(4)在windows10上搭建django开发虚拟环境

python学习笔记--开发与调试环境(4)在windows10上搭建django开发虚拟环境

作者:互联网

1 由于windows自带的dos不是很好用,下载git bash,这样可以在windows下敲inux命令

    例如在dos上查看目录里的子目录和文件,用【dir】,而在git bash上用【ls】。

    当然对于其他linux常用命令都是支持的,比如【pwd】【mkdir】【source】

2 下载并安装python3,在安装过程中勾选同时安装pip

安装完以后,可以在git bash下敲入命令查看

wenca@WENCA-N8P9G MINGW64 ~
$ python -V
Python 3.7.3

wenca@WENCA-N8P9G MINGW64 ~
$ pip -V
pip 19.0.3 from c:\program files\python37\lib\site-packages\pip (python 3.7)

wenca@WENCA-N8P9G MINGW64 ~
$ pip list
Package    Version
---------- -------
Django     2.2.4
pip        19.0.3
pytz       2019.2
setuptools 40.8.0
sqlparse   0.3.0
virtualenv 16.7.2

3 开始搭建虚拟环境

3.1 新建一个目录,用于专门存放各个项目虚拟环境

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python
$ mkdir virtual_environment

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python
$ ls
virtual_environment/

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python
$ cd virtual_environment/

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment

3.2 新建一个特定项目虚拟环境

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$ virtualenv signup_signin
Using base prefix 'c:\\program files\\python37'
New python executable in C:\Users\wenca\Desktop\Python\virtual_environment\signup_signin\Scripts\python.exe
Installing setuptools, pip, wheel...

安装完成后,可以查看虚拟环境下的目录结构

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$ ls signup_signin/
Include/  Lib/  LICENSE.txt  Scripts/  signup_signin/

3.3 进入到虚拟环境

wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$ source signup_signin/Scripts/activate

进入虚拟环境后,提示部分变成,最上面以后为【(虚拟环境名)】

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$

3.4 安装项目所需要的各种库,例如本文的django项目,需要djano框架库

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$ pip install django

安装完以后,可以查看

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$ pip list
Package    Version
---------- -------
Django     2.2.4
pip        19.0.3
pytz       2019.2
setuptools 40.8.0
sqlparse   0.3.0
virtualenv 16.7.2

3.5 开始创建django项目

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment
$ cd signup_signin/

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin
$ django-admin startproject signup_signin

完成以后,会在当前路径下新增一个目录signup_signin/,并且里面还有其他子目录和文件

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin
$ ls
Include/  Lib/  LICENSE.txt  Scripts/  signup_signin/
(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin
$ ls signup_signin/
db.sqlite3  manage.py*  signup_signin/

3.6 创建app

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin
$ cd signup_signin/

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin/signup_signin

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin/signup_signin
$ python manage.py startapp signup

3.7 运行django框架提供给开发者的web服务器

(signup_signin)
wenca@WENCA-N8P9G MINGW64 ~/Desktop/Python/virtual_environment/signup_signin/signup_signin
$ python manage.py runserver 5000

  此时会弹出日志信息

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 12, 2019 - 21:20:23
Django version 2.2.4, using settings 'signup_signin.settings'
Starting development server at http://127.0.0.1:5000/
Quit the server with CTRL-BREAK.

3.8 测试框架是否正常运行

用浏览器打开【http://127.0.0.1:500】链接,结果如下所示,说明一切正常。

 

标签:N8P9G,python,signup,windows10,MINGW64,signin,虚拟环境,WENCA,wenca
来源: https://blog.csdn.net/Wendy019900107/article/details/99336989