Is it necessary to activate Django Virtual Environment every time i restart my vscode Django

Is it necessary to activate the virtual environment? How can we re-enter/re-activate the already existing environment in Django? I shut down my computer and when I reopen the vs code the the '(venv)' mark is not there in the terminal before the locationenter image description here

Also is this the reason why I am getting the error ImportError: cannot import name 'static' from 'django.conf'

Upvotes: 1

Views: 788

Answers (4)

Irfan Ahmad
Irfan Ahmad

Reputation: 61

1- In VS code, in the bottom right corner you can select a python interpreter. From here select your python from your venv and it will be always available to the project, even after a restart. It will usually activate the venv in your terminal too.

2- Another way is adding a /.vscode/settings.json to customize your development environment. You can add this setting in your settings.json "python.terminal.activateEnvironment": true,

Upvotes: 0

Mike Oyibo
Mike Oyibo

Reputation: 1

Yes you have to. Open a new bash terminal and enter the command: xxxx/Scripts/activate.bat

where xxx is the folder wherein the initial virtual environment was created in.

After that, be sure to check that the terminal displays (xxx) before the bash prompt $.

For completeness, kindly open another terminal. This works for me on vscode.

Upvotes: 0

dfrazier
dfrazier

Reputation: 1

You can select the python interpreter at the button left of vscode. To find that path, you can find the folder to ur venv and look for the pythonw.exe in the Scripts folder.

Upvotes: 0

Mahdi mehrabi
Mahdi mehrabi

Reputation: 1734

Yes it is necessary to activate the virtual environment

by activating your virtual environment the packages you install with pip will install in your virtual environment not your system global python

by installing python extension on your vscode you can select your python interpreter to activate your virtual environment everytime you open vscode terminals

to do that first install that extension then press ctrl + shift + p and type

Python: Select Interpreter

Upvotes: 2

Related Questions