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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3 venv虚拟环境创建与安装Django相关的知识,希望对你有一定的参考价值。

创建虚拟环境

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

python3

python3



激活虚拟环境

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

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

python3


(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


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

(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.

以上是关于python3 venv虚拟环境创建与安装Django的主要内容,如果未能解决你的问题,请参考以下文章

Python3 venv 创建虚拟环境

ubuntu 下创建python环境

python3.5以后venv创建/激活/退出虚拟环境

python3 venv 虚拟环境使用方法

使用 virtualenv/venv 和 pip 管理虚拟环境

如何用python创建虚拟环境?掌握这些技术你才能真正的进步