2

Is it necessary to install separate django for each project? if yes then why? and if no then when i check for django version when virtualenv is not activated their is no error as below

E:\web\python\django_1>python -m django --version
2.1.4

And when i activate virtual env i get error as below

(django_1-Gx7XQ45n) E:\web\python\django_1>python -m django --version
C:\Users\usr_name\.virtualenvs\django_1-Gx7XQ45n\Scripts\python.exe: No module named django

Why this is happening?

gaurav
  • 415
  • 5
  • 12
  • try checking your path, seems its not pointing to the correct path. also see https://stackoverflow.com/questions/9462212/import-error-no-module-named-django – nyulan Jan 19 '19 at 03:13

2 Answers2

3

Basically Yes, you'll need to install django for each project when you are using virtual environment. That's because when you are using django for dynamic build up there are several projects with different requirements and different versions.

And, Such that when you have typed "python -m django --version 2.1.4", basically the django is installed on a particular virtual environment with all supported functionalities and requirements to that virtual environment.

So, you need to install django for each new virtual environment.

Try these command to install "pip install django".

Suvidh Jain
  • 101
  • 1
2

The virtualenv need to isolate every project. Each project have own requrements which may not require by other projects. So, we need to seperate virtualenv.

Firstly, you try to check django version without activating virtualenv, it will show django version. This is because you have a install django version on global python environment. To check it, you can uninstall django from global env try to run pip uninstall django without activating virtualenv.

Secondly, you activate vvirtualenv but checking django version failed. Because the virtualenv you activate, doesn't have a install ed django. Try to install by pip install django when virtualenv is activated. Then check django version.

shafik
  • 6,098
  • 5
  • 32
  • 50