Anybody get django cookiecutter to work with anaconda instead of virtualenv?

340 views Asked by At

Just when I think I'm starting to get a handle with django I start reading Two Scoops Of Django where they advise to use Cookiecutter instead of the regular django-admin startproject. The authors of Two Scoops are big on virtualenv. I've been using Anaconda because everywhere says it's better than virtualenv. I'm tempted to get rid of anaconda and just use virtualenv to try to get this to work, but figured I'd ask here first.

Anybody know how to get cookiecutter to work with Anaconda???

1

There are 1 answers

3
Nick Brady On

I think you're a bit confused about what anaconda actually is and what a virtual environment is. At the end of the day, they are both just python installations that (hopefully) include the binaries needed to run your code.

The answer to your question is to use a virtual environment, not anaconda for your project, then store your dependencies in a requirements.txt file so that anyone that has your project base code can install the exact dependencies needed for the project to their virtual environment.

So, what is the difference? Anaconda is essentially python with a bunch of preinstalled libraries geared towards data analysis. This means you as a programmer don't have to worry about installing matplotlib, pandas, or a plethora of other libraries. It also includes a binary that executes python code.

A virtual environment is essentially a barebones python environment. It literally copies the binaries needed to run python code to wherever you create your virtual environment. I typically create an environment in my local directory like this (python 3.6+):

python -m venv .venv

which will create a virtual environment in my current directory in the hidden directory .venv. I can install dependencies to this environment as needed for my project after setting it to my default interpreter using source. e.g.

source .venv/bin/activate

You'll notice that if you run which python, it'll now point to your shell instead of what the default python was before hand.. for example,

$ which python
/Users/you/path/to/.venv

now you would install your depencies as needed.. i.e.

pip install <library>

or even better

pip install requirements.txt