在 Django 中设置虚拟环境 [英] Setting up virtual environment in Django

查看:50
本文介绍了在 Django 中设置虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习 django,对如何设置虚拟环境很困惑.

i just started learning django and i am very confused in how to set up a virtual environment.

我已经成功安装了python:

i have successfully installed python:

当我运行 python --version 我得到Python 3.8.1

当我运行 python3 --version 我得到Python 3.8.1

我的第一个问题是当我运行 which -a python3 我得到这个

My first problem is when i run which -a python3 i get this

/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

/usr/local/bin/python3

/usr/bin/python3

有人能帮我理解为什么我有 3 个地方存在 python3 吗?

Can someone help me understand why i have 3 locations where python3 exist?

我的第二个问题是我已经成功安装了 virtaulenvvirtualenvwrapper

My 2nd problem is i have successfully installed virtaulenv and virtualenvwrapper

当我运行 virtualenv --version 我得到:

virtualenv 20.4.3 来自/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/virtualenv/__init__.py

当我运行 virtualenvwrapper --version 我得到:

-bash: virtualenvwrapper: command not found

这就是为什么当我运行 mkvirtualenv test 时,我一直找不到命令.

thats why when i run mkvirtualenv test i keep getting command not found.

我的第三个问题是virtualenv testmkvirtualenv test有什么区别?

My third problem is what is the difference between virtualenv test and mkvirtualenv test?

推荐答案

如果您使用的是 Ubuntu,您可以按照以下步骤操作

  1. 转到要保存 Django 项目的文件夹
  2. 运行命令python -m venv env
  3. env 是虚拟环境的名称,如果 python 不起作用,请尝试使用 python3
  4. activate environment by source env/bin/activate env 是环境的名称.
  5. 安装所有依赖项,创建一个新文件夹并在其中导入 Django 项目.
  1. Go to the folder where you intend to keep your Django project
  2. Run the command python -m venv env
  3. env is the name of virtual env if python doesn't work try with python3
  4. activate environment by source env/bin/activate env is the name of environment.
  5. Install all dependencies make a new folder and import Django project in it.

这篇关于在 Django 中设置虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆