[Answered ]-Python – Reactivating my virtualenv for django project

1👍

Visual studio code actually has a convenient way of keeping track of virtual environments. At the very bottom in the blue footer bar, click next to the refresh icon, and you should see whether it’s available.

If it’s really gone, don’t sweat it. Virtual environments are completely expendable – it’ll turn up. For now, just make another, and be sure you create it in your project’s root directory this time.

You actually usually don’t need to activate a venv with vscode. Just cd into the project root directory and open vscode with code .. The activated envionment will appear in that same spot in the footer.

Also, look into using a requirements.txt file, it’ll save a lot of time if you keep misplacing the virtualenv.

And finally, it’s best not to name your venv "virtualenv", name it something unique – otherwise it’s guaranteed to confuse!

0👍

If using Windows kindly follow the given steps to CREATE VIRTUAL ENVIRNMENT
So basically there are 4 steps involved in this:

a) Opening CMD

b) Navigating to the destination where you want to create your Django Project

c) Creating & Activating your virtual env

d) Checking if virtual env is enabled

  1. Open CMD (Press Windows key + R) then a Pop-up will appear inside it type – CMD.
    CMD containing a black screen is now open.
  2. Now navigate to folder where you want to create your django project using "cd"
    command
  3. Once a folder is created (mkdir Folder_name), go inside the folder using cd 7
    type following command
  4. python -m venv Environment_Name
  5. cd Environment_Name
  6. cd Scripts
  7. activate
  8. cd ..
  9. cls ( to clear the screen)

To check if virtual environment is enabled or not:

  1. We are still in Virtual Environment type following commands by
    downloading django in VE & checking it’s version
  2. pip install django
  3. import django
  4. django .version ((Double underscore before & after version it’s now
    showing here))

Now to Create our First Application inside VE type the following commands:

  1. django-admin startproject Project_NAME_of_your_choice
    (a folder with above name will be created inside VE)
  2. code . (This will open VS_Code)

To reconnect to virtual environment once PC goes switch off

  1. Open CMD & navigate folder using "cd" command-
    Folder_Created_for_Django_Project -> (inside it is VE folder) -> Go inside that VE folder & type the following commands –

Same as above point 5,6 & 7

  1. cd Environment_Name
  2. cd Scripts
  3. activate
  4. cd ..

You are re-connected to Virtual Environment..

Leave a comment