How to use aliases and postactivate with virtualenvwrapper to make easier your development tasks.

This is just a TIP, you can follow it or create yours based on it as well.

I like to use virtualenvwrapper for my Django and Python projects. I usually add some alias to postactivate file in order to avoid type a lot of commands with frequent tasks (reset default testing data for example).

So this is quite simple you just need to add aliases according your needs and practices.

Step 1: Locate and open with some text editor your postactivate script:


sergio$ vim ~/.virtualenvs/your_project_name/bin/postactivate

Step 2: Add aliases and save:


alias code_review='flake8 . --ignore=E501,F403'
alias migrate='rm your_project/db.sqlite3 && python makemigrations && python migrate'

Step 3: Activate (or deactivate and activate) your environment to test your aliases:

e.g activate:

sergio$ workon your_project

e.g deactivate and activate

(your_project) sergio$ deactivate
sergio$ workon your_project

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.