Installing Node.js Packages And Ruby Gems In Virtualenv

When you’re using Python’s virtualenv in your project, there might come a time when you’re going to be required to use libraries in other languages. When that happens, chances are you might want to have them installed in your virtual environment as well.

This tutorial from 2general will show you how to do just that using Node.js packages and Ruby gems. They also recommend using virtualenvwrapper, which you can put in your postactivate script. First thing you have to do is to set the variables:

# node.js packages
export npm_config_prefix=$VIRTUAL_ENV
# ruby gems
export GEM_HOME=$VIRTUAL_ENV
 export GEM_PATH=""

Installing Node.js packages

If you’re going to install the Less CSS compiler in the environment, for example, just use:

$ npm install -g less

The lessc script will be symlinked into $VIRTUAL_ENV/bin, which by the way requires a recent version of Node.js:

$ echo "div { a { color: #f00; } }" > my.less
$ lessc my.less
div a {
color: #f00;
 }

And if you’re on an Ubuntu box, the easiest way to get one is the following (tested on 11.10 and 12.04):

$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
 $ sudo apt-get install -y npm

Installing Ruby gems

Just use:

$ gem install sass

The script will be installed inside $VIRTUAL_ENV/bin; the same as Node.js.

$ echo "div { a { color: #f00; } }" > my.scss
$ sass my.scss
div a {
 color: #f00; }

Credits to the guys at 2General for the tip!

 

Incoming search terms for the article:

Related Posts

How To Create A Webpage With A Clean Style Portfolio Layout

How to Create a Sparkling Diamond and Gold Text Effect

Creating Colorful Effects in Photoshop

Creating a Cool Drunken Monkey Illustration