注意:
⭐前提:安装了annaconda(python版本管理工具),如果没有安装,强烈建议安装一下!!!
操作:
前言:
这里新创建一个名为"python_3.11_start_django"的conda环境
创建的新的django项目名称为:start_django
步骤如下:
1、新建 conda环境 conda create --name python_3.11_start_django
2、创建conda环境过程中,出现Proceed ([y]/n)?
输入 y
3、查询已安装的conda环境列表 conda env list
4、切换/激活到所需conda环境,这里是 python_3.11_start_django activate python_3.11_start_django
5、安装django环境 pip install django
6、创建一个新的django项目django-admin startproject start_django
7、切换到 start_django 目录下 cd start_django
8、查看start_django项目路径下的所有文件: dir /s /a
操作示例如下:
powershell
# 1、安装python环境
E:\notes\django\django项目学习\配置Django环境>conda create --name python_3.11_start_django python=3.11
Retrieving notices: ...working... done
Channels:
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\Administrator\.conda\envs\python_3.11_start_django
added / updated specs:
- python=3.11
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2024.9.24 | haa95532_0 131 KB
python-3.11.10 | h4607a30_0 18.7 MB
setuptools-75.1.0 | py311haa95532_0 2.2 MB
tzdata-2024b | h04d1e81_0 115 KB
------------------------------------------------------------
Total: 21.2 MB
The following NEW packages will be INSTALLED:
bzip2 pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_6
ca-certificates pkgs/main/win-64::ca-certificates-2024.9.24-haa95532_0
libffi pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
openssl pkgs/main/win-64::openssl-3.0.15-h827c3e9_0
pip pkgs/main/win-64::pip-24.2-py311haa95532_0
python pkgs/main/win-64::python-3.11.10-h4607a30_0
setuptools pkgs/main/win-64::setuptools-75.1.0-py311haa95532_0
sqlite pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
tk pkgs/main/win-64::tk-8.6.14-h0416ee5_0
tzdata pkgs/main/noarch::tzdata-2024b-h04d1e81_0
vc pkgs/main/win-64::vc-14.40-h2eaa2aa_1
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.40.33807-h98bb1dd_1
wheel pkgs/main/win-64::wheel-0.44.0-py311haa95532_0
xz pkgs/main/win-64::xz-5.4.6-h8cc25b3_1
zlib pkgs/main/win-64::zlib-1.2.13-h8cc25b3_1
# 2、 输入y ,确认安装!
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate python_3.11_start_django
#
# To deactivate an active environment, use
#
# $ conda deactivate
# 3、查询已安装的conda环境列表
E:\notes\django\django项目学习\配置Django环境>conda env list
# conda environments:
#
python_3.11_start_django C:\Users\Administrator\.conda\envs\python_3.11_start_django
base D:\python\Anaconda3
# 4、切换/激活到所需conda环境,这里是 python_3.11_start_django
E:\notes\django\django项目学习\配置Django环境>activate python_3.11_start_django
# 5.1、尝试新建django项目,发现报错!!
(python_3.11_start_django) E:\notes\django\django项目学习\配置Django环境>django-admin startproject start_django
'django-admin' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
# 5.2、上述报错表示未安装django依赖包,"pip install django" 安装django最新版本的依赖包
(python_3.11_start_django) E:\notes\django\django项目学习\配置Django环境>pip install django
Collecting django
Downloading Django-5.1.2-py3-none-any.whl.metadata (4.2 kB)
Collecting asgiref<4,>=3.8.1 (from django)
Using cached asgiref-3.8.1-py3-none-any.whl.metadata (9.3 kB)
Collecting sqlparse>=0.3.1 (from django)
Using cached sqlparse-0.5.1-py3-none-any.whl.metadata (3.9 kB)
Collecting tzdata (from django)
Downloading tzdata-2024.2-py2.py3-none-any.whl.metadata (1.4 kB)
Downloading Django-5.1.2-py3-none-any.whl (8.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.3/8.3 MB 1.5 MB/s eta 0:00:00
Using cached asgiref-3.8.1-py3-none-any.whl (23 kB)
Using cached sqlparse-0.5.1-py3-none-any.whl (44 kB)
Downloading tzdata-2024.2-py2.py3-none-any.whl (346 kB)
Installing collected packages: tzdata, sqlparse, asgiref, django
Successfully installed asgiref-3.8.1 django-5.1.2 sqlparse-0.5.1 tzdata-2024.2
# 5.3、django依赖包完成后,再次尝试创建django项目,发现无报错信息。
(python_3.11_start_django) E:\notes\django\django项目学习\配置Django环境>django-admin startproject start_django
# 6、使用 dir 查看当前目录下是否有刚刚创建的django项目文件夹
(python_3.11_start_django) E:\notes\django\django项目学习\配置Django环境>dir
驱动器 E 中的卷是 本地磁盘
卷的序列号是 6BC6-B098
E:\notes\django\django项目学习\配置Django环境 的目录
2024/10/18 22:30 <DIR> .
2024/10/18 22:25 <DIR> ..
2024/10/18 22:30 <DIR> start_django
0 个文件 0 字节
3 个目录 24,283,156,480 可用字节
# 7、切换到该项目目录中
(python_3.11_start_django) E:\notes\django\django项目学习\配置Django环境>cd start_django
# 8、查看该项目目录下的所有文件夹和文件信息
(python_3.11_start_django) E:\notes\django\django项目学习\配置Django环境\start_django>dir /a /s
驱动器 E 中的卷是 本地磁盘
卷的序列号是 6BC6-B098
E:\notes\django\django项目学习\配置Django环境\start_django 的目录
2024/10/18 22:30 <DIR> .
2024/10/18 22:30 <DIR> ..
2024/10/18 22:30 690 manage.py
2024/10/18 22:30 <DIR> start_django
1 个文件 690 字节
E:\notes\django\django项目学习\配置Django环境\start_django\start_django 的目录
2024/10/18 22:30 <DIR> .
2024/10/18 22:30 <DIR> ..
2024/10/18 22:30 417 asgi.py
2024/10/18 22:30 3,362 settings.py
2024/10/18 22:30 792 urls.py
2024/10/18 22:30 417 wsgi.py
2024/10/18 22:30 0 __init__.py
5 个文件 4,988 字节
所列文件总数:
6 个文件 5,678 字节
5 个目录 24,283,156,480 可用字节