This will build on the PyEnv / Bash / OSX installation on Mac blog post i wrote some time ago in order to be able to have a set of packages in a virtual environment set only for my Django project. So, lets get started!

Environment Setup

The first thing is change into a directory that will hold my project files by running the following

mkdir myapp && cd $_

Just for the sake of versioning my application, i'm going to create a README.md and initialize my repo:

echo '# My App' >> README.md
touch .gitignore
git init
git add .
git commit -m 'Initialize repo'

Now, set a local python version within that directory:

pyenv local 3.6.2

and install virtual environment which is the last step to be able to get started setting up the project:

pip install virtualenv

Project Setup

Now it's time to get my Django app started by creating a project specific virtual environment. Bare in mind we don't want to version this directory so:

virtualenv .env
echo '.env' >> .gitignore
echo 'db.sqlite3' >> .gitignore
echo '*.pyc' >> .gitignore
source .env/bin/activate
pip install django
pip freeze > requirements.txt
django-admin.py startproject myapp .
chmod +x ./manage.py
git commit -m 'Install empty Django project'

And that should do the job! now simply run the initial migration and server:

./manage.py migrate
./manage.py runserver

and go to http://127.0.0.1:8000/ and mission accomplished!