Coder Social home page Coder Social logo

config-virtualenv's Introduction

VirtualEnv Config

This allows you to easily jump from project to in different virtual environments even easier. All credit is due to the infamous Dan Sackett whom I forked this from and revised for my own use.

Usage

Create an environment and work on it

$ mkvirtualenv <name>

Deactivate a virtual environment

$ deactivate

Work on a virtual environment

$ workon <name>

Remove a virtual environment

$ rmvirtualenv <name>
# (Then proceed to remove your project folder)

Installation

Auto Installation

Run the following command (You might have to $ chmod +x autorun.sh):

$ bash autorun.sh

Manual Installation

1: Install Packages

Install Python PIP (Package Manager) if not already installed.

sudo apt-get install python-setuptools
sudo easy_install pip

Globally Install our two items

sudo pip install virtualenv virtualenvwrapper

2: Centralize the VirtualEnv settings

mkdir ~/.virtualenvs
echo "export WORKON_HOME=~/.virtualenvs" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
echo "export PIP_VIRTUALENV_BASE=~/.virtualenvs" >> ~/.bashrc

3: Alias Creation

echo "alias mkvirtualenv='mkvirtualenv --no-site-packages --distribute'" >> ~/.bashrc

And Reload!

source ~/.bashrc

4: Setup VirtualEnv Hooks

Edit your postactivate file (~/.virtualenvs/postactivate):

# source postactivate hook
_HOOK_PATH=bin/postactivate
_PROJECT_FILE=$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME

if [ -s $_PROJECT_FILE ]; then
    export _PROJECT_DIR=$(cat $_PROJECT_FILE)
    _HOOK=$_PROJECT_DIR/$_HOOK_PATH
    [ -f $_HOOK ] && . $_HOOK
fi

Your postdeactivate file (~/.virtualenvs/postdeactivate):

# source postdeactivate hook
_HOOK_PATH=bin/postdeactivate

if [ -n "$_PROJECT_DIR" ]; then
    _HOOK=$_PROJECT_DIR/$_HOOK_PATH
    [ -f $_HOOK ] && . $_HOOK
    unset _PROJECT_DIR
fi

Your postmkvirtualenv file (~/.virtualenvs/postmkvirtualenv):

NOTE: If you are not storing files in ~/projects/ Then change it here!

#!/bin/bash
# This hook is run after a new virtualenv is activated.

proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
[ ! -d ~/projects/$proj_name ] && mkdir -p ~/projects/$proj_name
add2virtualenv ~/projects/$proj_name
cd ~/projects/$proj_name

Your predeactivate file (~/.virtualenvs/predeactivate)::

#!/bin/bash
# This hook is run before every virtualenv is deactivated.

cd

config-virtualenv's People

Contributors

codezues avatar dansackett avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.