Christian LSANGOLA
Christian LSANGOLA

Reputation: 3317

Should I always use virtualenvs in Django?

I'm a beginner, and I'm learning Django for web development. So I want to know for my little test, should in always have a virtualenv or can I continue to learn without installing it? I've asked because in youtube Django videos, some instructors are installing it, and others aren't.

Upvotes: 0

Views: 1625

Answers (5)

Someone3
Someone3

Reputation: 81

No. It's not mandatory to use virtualenvs but it might help.

I think you need to understand what virtualenvs does and when to use it. What virtualenvs does is creating an isolated environment(for example, a django project) from others. It's not just a Django component. It can be used for other projects as well.

Let's assume that there are two different projects, A and B. It doesn't matter if they are Django projects.

In project A, you might want to use python module AAA(version 1.00). And in project B, you also want to use python module AAA(version 2.00). Both use the same module but their versions are different.

In those cases you can use virtualenvs to create two different environments and isolate those. And install AAA version 1.0, AAA version 2.0 in those environment respectively.

When people start a new project, it's very natural and common to create a new isolated environment only for it. Then it would be easy to move the project to another computer or recreate exactly the same environment in other machines. Also it won't be affected by other previously installed modules or configuration. If there are other modules before your project might work differently and you might not find that until you deploy.

So it's not mandatory but using it is a good practice.

Also there are many tools for creating an isolated environment in different layers like Conda, Docker etc... Take a look at those as well.

Upvotes: 3

lexotero
lexotero

Reputation: 66

Your question is:

Can I continue without installing it?

So the answer is yes.

The virtualenv is not a requirement to set up a Django project. Nevertheless, you will eventually use virtualenvs in the future when you are more aware of dependencies, so why don't you start to learn now how to use them?

A virtualenv is not the only solution to isolate your project's dependencies but is the most commonly used in Python developments.

Upvotes: 1

thumbtackthief
thumbtackthief

Reputation: 6221

There's no good reason not to that I know of, and speaking as someone who did not when I first started learning and messed up my system in such a way that it took months to fix, I'd highly recommend them. You'll most likely be using them in whatever job you eventually get, so it's a good and easy thing to learn.

Virtualenv-burrito is a quick and easy way to get everything set up.

https://github.com/brainsik/virtualenv-burrito

Upvotes: 3

cezar
cezar

Reputation: 12032

This is to some extent an opinion based question, but because it concerns good practices I'd like to drop few lines.

Some instructors in Django videos don't say anything about virtualenvs, maybe because their course aims at Django and not virtualenvs and their videos can't have it all.

It is generally a good practice to use virtual environments for Python, especially for web development. You'll start with some tutorial and use certain version of Django. For your next project, you'd like eventually to go with the latest or maybe the LTS version. Don't mess everything by installing packages globally as root.

Beyond virtualenv I'd strongly recommend using virtualenvwrapper, which makes the use of virtual environments a real pleasure.

Upvotes: 1

user378704
user378704

Reputation:

From the hitchhiker's guide to python

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

Meaning if you install all your packages in your local environment, it could collide when you work on multiple projects. Hence having a virtualenv for each project is considered a fail safe.

Upvotes: 6

Related Questions