Me gustaría instalar un script de nodejs (lessc) en un virtualenv.
Cómo puedo hacer eso ?
Gracias
Natim
Me gusta la respuesta de Shorrty, me recomendó usar nodeenv, ver: ¿existe un entorno virtual para node.js?
Seguí esta guía: http://calvinx.com/2013/07/11/python-virtualenv-with-node-environment-via-nodeenv/
Todo lo que tenía que hacer era:
. ../bin/activate # switch to my Python virtualenv first pip install nodeenv # then install nodeenv (nodeenv==0.7.1 was installed) nodeenv --python-virtualenv # Use current python virtualenv npm install -g less # install lessc in the virtualenv
Aquí está lo que usé hasta ahora, pero creo que puede estar optimizado.
Instalar nodejs
wget http://nodejs.org/dist/v0.6.8/node-v0.6.8.tar.gz tar zxf node-v0.6.8.tar.gz cd node-v0.6.8/ ./configure --prefix=/absolute/path/to/the/virtualenv/ make make install
Instalar npm (Administrador de paquetes de nodo)
/absolute/path/to/the/virtualenv/bin/activate curl https://npmjs.org/install.sh | sh
Instalar lesscss
npm install less -g
Cuando activa su virtualenv puede usar lessc
Creé un script de bash para automatizar la solución de Natim.
Asegúrate de que tu Python virtualenv esté activo y solo ejecuta el script. NodeJS, NPM y lessc se descargarán e instalarán en su virtualenv.
#!/bin/sh # # This script will download NodeJS, NPM and lessc, and install them into you Python # virtualenv. # # Based on a post by Natim: # http://stackoverflow.com/questions/8986709/how-to-install-lessc-and-nodejs-in-a-python-virtualenv NODEJS="http://nodejs.org/dist/v0.8.3/node-v0.8.3.tar.gz" # Check dependencies for dep in gcc wget curl tar make; do which $dep > /dev/null || (echo "ERROR: $dep not found"; exit 10) done # Must be run from virtual env if [ "$VIRTUAL_ENV" = "" ]; then echo "ERROR: you must activate the virtualenv first!" exit 1 fi echo "1) Installing nodejs in current virtual env" echo cd "$VIRTUAL_ENV" # Create temp dir if [ ! -d "tmp" ]; then mkdir tmp fi cd tmp || (echo "ERROR: entering tmp directory failed"; exit 4) echo -n "- Entered temp dir: " pwd # Download fname=`basename "$NODEJS"` if [ -f "$fname" ]; then echo "- $fname already exists, not downloading" else echo "- Downloading $NODEJS" wget "$NODEJS" || (echo "ERROR: download failed"; exit 2) fi echo "- Extracting" tar -xvzf "$fname" || (echo "ERROR: tar failed"; exit 3) cd `basename "$fname" .tar.gz` || (echo "ERROR: entering source directory failed"; exit 4) echo "- Configure" ./configure --prefix="$VIRTUAL_ENV" || (echo "ERROR: configure failed"; exit 5) echo "- Make" make || (echo "ERROR: build failed"; exit 6) echo "- Install " make install || (echo "ERROR: install failed"; exit 7) echo echo "2) Installing npm" echo curl https://npmjs.org/install.sh | sh || (echo "ERROR: install failed"; exit 7) echo echo "3) Installing lessc with npm" echo npm install less -g || (echo "ERROR: lessc install failed"; exit 8) echo "Congratulations! lessc is now installed in your virtualenv"
Proporcionaré mi solución genérica para trabajar con Gems y NPMs dentro de un soporte virtualenv Gems y Npm para personalizar a través de la configuración env: GEM_HOME
y npm_config_prefix
Puede pegar el fragmento a continuación en su postactivate
o activate
script (es más importante si usa virtualenvwrapper
o no)
export GEM_HOME="$VIRTUAL_ENV/lib/gems" export GEM_PATH="" PATH="$GEM_HOME/bin:$PATH" export npm_config_prefix=$VIRTUAL_ENV export PATH
Ahora, dentro de su virtualenv, todas las bibliotecas instaladas a través de gem install
o npm -g install
se instalarán en su virtualenv y se agregará el binario en su PATH
si está usando virtualenvwrapper
tu $VIRTUALENVWRAPPER_HOOK_DIR
Esta solución no cubre la instalación de nodejs dentro del virtualenv, pero creo que es mejor delegar esta tarea en el sistema de empaquetado (apt, yum, brew …) e instalar node y npm globalmente
Editar:
Recientemente creé 2 plugin para virtualenvwrapper para hacer esto automáticamente. Hay uno para gem y npm: