Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Django - 创建虚拟环境


虚拟环境

建议每个 Django 项目都使用一个专用的虚拟环境,而管理虚拟环境的一种方法是 venv,它包含在 Python 中。

虚拟环境的名称由您选择,在本教程中,我们将称它为 myworld

在命令提示符中键入以下内容,请记住导航到您想要创建项目的目录

Windows

py -m venv myworld

Unix/MacOS

python -m venv myworld

这将设置一个虚拟环境,并创建一个名为“myworld”的文件夹,其中包含子文件夹和文件,如下所示

myworld
  Include
  Lib
  Scripts
  pyvenv.cfg

然后,您必须通过键入以下命令激活环境

Windows

myworld\Scripts\activate.bat

Unix/MacOS

source myworld/bin/activate

激活环境后,您将在命令提示符中看到此结果

Windows

(myworld) C:\Users\您的用户名>

Unix/MacOS

(myworld) ... $

注意:每次打开命令提示符以处理项目时,都必须激活虚拟环境。


安装 Django

下一章中,您将最终学习如何安装 Django!



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.