How to activate Virtual Environment in DJango
Asked Answered
A

11

7

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!

Ause answered 13/3, 2019 at 13:14 Comment(1)
Possible duplicate of Python virtualenv questionsMonahan
S
28

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
Seeder answered 13/3, 2019 at 13:20 Comment(1)
Instead of opening CMD in normal mode, the best way is run as administrator or run PowerShell normally.Suggestive
G
3
  1. go to project directory ( in which the virtual environment directory exist)
  2. In Ubuntu Linux user type following command: source yourenvironmentname/bin/activate
Gramme answered 26/8, 2021 at 10:50 Comment(0)
I
2

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
Insuppressible answered 2/8, 2019 at 6:24 Comment(0)
G
0

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 
Groggery answered 13/3, 2019 at 13:22 Comment(0)
I
0

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

Ikeikebana answered 13/3, 2019 at 13:55 Comment(2)
I just wanted to know, how to activate the .bat file from VS CODE! Please do let me know!Ause
@RoosyDepp, It will automatically find the .bat file from your Virtual Environment once it successfully created, If it is not finding then Copy the path where the .bat is in Virtual Environment than paste it in VS Code terminal like path\to\activate.batVichy
S
0

open command prompt and follow these steps:-

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>

Run the django project run this./manage.py runserver

Siusiubhan answered 29/2, 2020 at 14:58 Comment(0)
S
0
  1. use "cd ..\" to go back to the desired parent folder.
  2. Delete the initial venv folder in your parent folder where the venv exist.
  3. recreate the virtual environment with the name desired. The error actually means you are in a wrong folder Now, the pyvenv.cfg appears with the venv directory.
  4. execute the ".\Scritpts\activate" to activate. The command executed will go into the scripts folder in the venv folder to look for the activate.bat file (it's optional to append the .bat extension)
Stroh answered 12/5, 2020 at 21:32 Comment(0)
E
0

After creating the environment in django on windows os, to run at anytime, first of all make sure you know the correct already created environment name and start the tasks below:

  1. make sure to go in the specific directory where your project belong in command prompt
  2. then, type this command, WORKON (environment name)

Suppose your created environment is omsai, then type: workon omsai Thank you, this might help you

Exemplify answered 3/7, 2020 at 3:41 Comment(0)
L
0
  • open cmd in the virtual environment parent folder
  • type venv_folder_name\Scripts\activate
  • hit enter
Lieutenant answered 24/9, 2020 at 6:49 Comment(0)
S
0

In linux the command is

source myenv/bin/activate

here myenv is considered to be in the current directory

Scooter answered 8/5, 2021 at 13:5 Comment(0)
G
-1

Now it works,

api\project_name>.\venv\Scripts\activate

(venv) C:\PATH\api\covid_analysis_api>

by this way, it is neccesary to use cmd in windows rather than Powershell or Git bash.

in adition, I highly recommend to use .\venv\Scripts\activate as this web page indicate

https://mothergeo-py.readthedocs.io/en/latest/development/how-to/venv-win.html#activate-the-environment

Gormand answered 16/6, 2021 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.