python3 venv虚拟环境创建与安装Django

时间:2022-12-01 11:35:15

创建虚拟环境

C:\Users\Xiao>python -m venv D:\Pythonwork\venvtest

python3 venv虚拟环境创建与安装Django

python3 venv虚拟环境创建与安装Django



激活虚拟环境

C:\Users\Xiao>D:\Pythonwork\venvtest\Scripts\activate

(venvtest) C:\Users\Xiao>

python3 venv虚拟环境创建与安装Django


(venvtest) C:\Users\Xiao>python -V

Python 3.7.0

查看到当前使用的python版本

关闭虚拟环境命令如下:

(venvtest) C:\Users\Xiao>D:\Pythonwork\venvtest\Scripts\deactivate


安装包

(venvtest) C:\Users\Xiao>pip install Django==2.2.28 -i https://pypi.tuna.tsinghua.edu.cn/simple

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple

Collecting Django==2.2.28

Downloading https://pypi.tuna.tsinghua.edu.cn/packages/43/69/eaac9a827335898d626066989865974fa48bfc23efd1b34628d64543b2d9/Django-2.2.28-py3-none-any.whl (7.5MB)

100% |████████████████████████████████| 7.5MB 701kB/s

Collecting pytz (from Django==2.2.28)

Using cached https://pypi.tuna.tsinghua.edu.cn/packages/85/ac/92f998fc52a70afd7f6b788142632afb27cd60c8c782d1452b7466603332/pytz-2022.6-py2.py3-none-any.whl

Collecting sqlparse>=0.2.2 (from Django==2.2.28)

Using cached https://pypi.tuna.tsinghua.edu.cn/packages/97/d3/31dd2c3e48fc2060819f4acb0686248250a0f2326356306b38a42e059144/sqlparse-0.4.3-py3-none-any.whl

Installing collected packages: pytz, sqlparse, Django

Successfully installed Django-2.2.28 pytz-2022.6 sqlparse-0.4.3

You are using pip version 10.0.1, however version 22.3.1 is available.

You should consider upgrading via the 'python -m pip install --upgrade pip' command.


(venvtest) C:\Users\Xiao>

python3 venv虚拟环境创建与安装Django


进入虚拟环境目录创建项目

(venvtest) C:\Users\Xiao>d:

(venvtest) D:\>cd D:\Pythonwork\venvtest

(venvtest) D:\Pythonwork\venvtest>django-admin startproject mysite .

运行项目

(venvtest) D:\Pythonwork\venvtest>python manage.py runserver 5555

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.

December 01, 2022 - 09:52:59

Django version 2.2.28, using settings 'mysite.settings'

Starting development server at http://127.0.0.1:5555/

Quit the server with CTRL-BREAK.