How to activate Virtual Environment in DJango

≯℡__Kan透↙ 提交于 2020-01-25 08:19:05

问题


I am currently on Windows and the Venv is not getting activatedUnactivated ENV, Is there any way to fix this. Thanking you guys in advance! Help out a newbie!


回答1:


In windows: Press Windows (or Windows+R) and then type “cmd”: Run the Command Prompt in normal mode.

  1. cd C:\Users\user\Desktop\UserDjangoProject> pip install virtualenv
  2. For Create a venv run this virtualenv -p python3 venv
  3. Activate virtualenv venv\Scripts\activate
  4. It will look like this (venv) C:\Users\user\Desktop\UserDjangoProject>
  5. Then run pip install -r requirements.txt
  6. Run the django project run this./manage.py runserver



回答2:


I think you are calling the activate.bat script like a Unix environment, using: ./venv/Scripts/activate.bat

While in Windows you should call like this:

\venv\Scripts\activate.bat 



回答3:


To make easy here with visual studio code You have to create a venv at the root of your django project. If you have a project my_project then in the folder my_project you must have one (v) env in it. Thus visual studio code will be able to detect the environment. And so you'll be able to change the environment (python version) in the bottom left in visual studio code

example of project

├── book
├── db.sqlite3
├── env
├── manage.py
├── static
├── templates
└── tuto_signal

here the project name is tuto_signal and the env is at the same level of manage.py, book is an app created by ./manage.py startapp book.

Try to do like this an let me know the result.

Hope it can help you




回答4:


In Linux/Mac, go to the project folder (in which, there should be env folder created).

. my_env_name/bin/activate

In Windows, go to the project folder (in which, there should be env folder created).

my_env_name\Scripts\activate


来源:https://stackoverflow.com/questions/55142774/how-to-activate-virtual-environment-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!