Last Updated: September 27, 2021
· guangyi

Study note: Install and setup Djang_MongoDB_Engine

As a background, I just begin to study MongoDB and have a little knowledge of Django.
This is more like a study note to help me remember how did I finish every step.

I use Django + MongoDB +Django MongoDB Engine
And <a href="">this is the tutorial I followed to create a single user blog application.</a> But after I began to setup I find this bloc can only cover the installation and setup part...

To install and setup MongoDB, I use <a href=""> this tutorial</a>. I think it's detailed than the official one

1. install pip

I don't know why I didn't install it before....Here is the <a href="">steps </a>I followed to install pip

But I have to add "sudo" in front of the commands to get permission

Below are some very important steps...I messed up at first, and it took me a very long time to find out why! It almost drive me crazy...

2.install Django MongoDB Engine:

Following the <a href="">setup tutorial</a>

a: install virtualenv

$sudo pip install virtualenv

b: I'd like to create Django project first. Because we will use it later.
Change into the target directory, and input

$ startproject myproject

This will create a folder called "myproject" and under that folder there are some python files. One of them is called, another is

DO NOT skip step c and d to install the following python packages! Skipping those two step was a mistake I made which made the setup of DjangoMongoDBEngine so annoying....I had no idea what is virtualenv when I began to install the Engine, now I have better idea what it's for.

c:Set up a virtual environment for "myproject",

Not inside "myproject" folder, but in the container of "myproject" folder, use:

$virtualenv myproject

This will initialize the myproject folder with python site-package and something essential.
It will create /bin, /lib etc... folders.

d:Activate it use:

$source myproject/bin/activate

e: Make sure the virtual environment is active now! and then install Djang_nonrel and toolbox and that engine.

$sudo pip install git+

$sudo pip install -U git+

$pip install git+

3.Set up Django database:

In the find DATABASES, and do the changes as below.


'default' : {

      'ENGINE' : 'django_mongodb_engine',

      'NAME' : 'my_database'



4.Create my_database

in the terminal,to start the MongoDB server input


to start the database shell in another terminal window, input


in the database shell, to create and switch to my_database input:

use my_database

5.Test it:

under the "myproject" folder, where locates, try

$python runserver

If you see this:

Validating models...
0 errors found
Django version 1.3.7, using settings 'myproject.settings'
Development server is running at

Hurray! it success!

But you may also see some other errors like what i have experienced...Frustration.

1.If you see the error message, like 'djangomongodbengine' isn't an available database backend.. No module named utils" .

It may caused by not activating the environment. or if you do activate it, but still see this message, then the toolbox version is not correct. Make sure its version is 1.3. After I reinstall toolbox, it works!

2.You may also see this: "ImportError: No module named"

In my case, while activate the virtual environment, I will see this message. Go to /myproject/lib/python2.7/site-packages (you may use different python version ) if you couldn't find django, djangomongodbengine, djangotoolbox, that probably means when you install these packages, you are not activate the virtual environment! That's the mistake i made during the setuo. I also can't import django while in this virtual environment.

But probably you have other reasons other than mine, <a href="">this is a related stack overflow questions and answers</a> I think may helpful.

BTW, the first line in my is

#!/usr/bin/env python

I didn't change it.

These are almost every step and problems I encountered during the setup.

If you are newbie like me, I hope this is helpful~

I need to take a break now~~~~

1 Response
Add your response

I came across your great presentation on using Django and MongoDB. At the same time I am wondering if you are aware of djongo

It translates a SQL query string into a mongoDB query document. I can use the original django ORM without having to install a new ODM to get Django to work!

I wonder why you feel using MongoEngine is a better alternative. I am able to use all contrib modules like admin, using this connector. There is no additional effort of learning a new ODM either with this connector.

over 1 year ago ·