-->

Meaning of isolated Virtualenv in Django and what

2019-08-23 23:56发布

问题:

I am new to Django and I am more interested in how it works, I want to know more about its lib, configuration files, database linking etc. Can anyone suggest me good websites or tutorials?

Also, I want to know the meaning of Virtual env in Django. While installing Django we create a directory and create a virtual environment and in we install Django in active env, But virtualenv creates isolated Python environments.

My question is: What does isolated env mean?

I went through the definition of Virtualenv. But I am confused, if I have installed Django in an active env in a directory, it supposed to work within that directory (as I installed in active Virtualenv and it is isolated) and have to install Django every time I create a project, But we don't install Django every time we create a new project. So what is the scope of Django local copy that I installed on my system?

回答1:

Virtual Environment is provided by Python for Encapsulating your project in a directory along with its dependencies.

Frankly speaking, local Django copy is rarely used when you are working on multiple projects that are on different Django version.

But, if you're a beginner then i would strongly suggest to download the latest version of django and start practicing with it. No need to make virtualenv for every project as it downloads a lot of Libraries thus eating up your memory.

Also if 2 or more projects are of same django version which is different from your local one then run those two projects in a single virtualenv. i use pyenv, which is very easy to use.

If you want to know how to use pyenv

Django docs are the best if you want learn it.

Django Girls, there material is also commendable.

django book, more like a reference book, but its good.



回答2:

Virtual environment always be preferable when you are working on different projects in same system. Virtualenv creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments or with global libraries. Your django local copy will work only when you don't use vritualenv and start using global packages. Also you can't access the django from one virtualenv to another virtualenv. As they are isolated you need to install again in new virtaulenv.

Different projects having requirement of different libraries and their versions, which may be conflicts with each other if we use same environment for all projects and your work messed up. To avoid these kind of issues virtualenv is preferable. So whenever you are staring any new project, go for separate virtual env and start installing your packages.

I hope this will help you to understand.