eschn13
eschn13

Reputation: 13

Create the Django app or the virtual environment first?

I have been trying to successfully create projects using Django however I have seen projects where the user will create the project first THEN the virtual env. I have also seen instances where the user creates the virtual env and THEN the django app. Both sides argue that their method is better, but now I am confused. Pls help

Upvotes: 1

Views: 403

Answers (3)

Dimitris Kougioumtzis
Dimitris Kougioumtzis

Reputation: 2439

When you have a virtual environment you can track packages for each project. When virtual environment is activated you can create requirements.txt file with command

pip freeze > requirements.txt

So when you want to run the django project to a different os you can install your packages from the requirements file you have created.

pip install -r requirements.txt

An other scenario is when your os has django 1.11 and you have a django project created with that version. When you upgrade the django version in your os the the django application will break.

So i think that for each django project a good way is to have its own virtual environment

Upvotes: 0

sahasrara62
sahasrara62

Reputation: 11228

it is better to create the virtual environment first and start working in that environment. ie use python from that environment.

advantage:

a. environment will contain all the package required by the project

b. can switch between multiple env( testing purpose)

c. easy to keep a record of the required packages

d. will not affect another project where u need python 3.5 and in django project u require python 3.6

disadvantage: need to keep track of each env in case if you have many virtual env ( all virtual env are store in same place just like anaconda one, else if store in project folder then no issue for1 env)

Upvotes: 1

Spounka
Spounka

Reputation: 454

It depends on your usage. Let's say you have Django 2.1 installed globally, then you have a project where you need let's say Django 1.9, here you need to set-up your virtual environment first

Upvotes: 1

Related Questions