2012-01-24 25 views
15

Me gustaría instalar un script nodejs (lessc) en un virtualenv.¿Cómo instalar lessc y nodejs en un virtualenv de Python?

¿Cómo puedo hacer eso?

Gracias

Natim

+1

¿Puede proporcionarnos algunos consejos reales: qué es lessc y dónde puede uno encontrarlo? Tampoco entiendo cómo se mezclan virtualenv y node.js: virtualenv es para Python, mientras que node.js es una plataforma basada en JavaScript. – jsalonen

+0

'lessc': http://lesscss.org/ - Virtualenv es para el entorno python y proporciona algunos ejecutables en el entorno, me gustaría instalar lessc en este entorno. – Natim

Respuesta

15

me gusta la respuesta de shorrty, se recomienda el uso de nodeenv, consulte: is there an virtual environment for node.js?

que siguieron esta guía: http://calvinx.com/2013/07/11/python-virtualenv-with-node-environment-via-nodeenv/

Todo lo que tenía que hacer yo 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 
14

Aquí es lo que he usado hasta ahora, pero puede ser optimizado creo.

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 (nodo Administrador de paquetes)

/absolute/path/to/the/virtualenv/bin/activate 
curl https://npmjs.org/install.sh | sh 

Instalar lesscss

npm install less -g 

Al activar su virtualenv puede utilizar lessc

+0

npm no crea un enlace simbólico? – JuanPablo

+1

Parece que no funcionó. – Natim

+3

con 'sudo npm install less -g' el binario está instalado en'/usr/local/bin/lessc' – JuanPablo

3

me proporcionará mi solución genérica a las obras con las gemas y los MNP dentro de un virtualenv Gemas y apoyo Npm para personalizar a través de la configuración de env: GEM_HOME y npm_config_prefix

Usted puede pegue el siguiente fragmento de código en el script postactivate o activate (que es más cuestión si se utiliza o no virtualenvwrapper)

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 librerías instaladas a través de gem install o npm -g install se instalará en su virtualenv y binarios añade en su PATH si está utilizando virtualenvwrapper se puede hacer el cambio global a toda su virtualenv si modifica el postactivate que viven dentro de su $VIRTUALENVWRAPPER_HOOK_DIR

Esta solución no cubren nodejs instalar en el interior del virtualenv pero creo que es mejor delegar esta función en el sistema de paquetes (apt, yum, cerveza ..) e instalar nodo y NPM a nivel mundial

Editar:

recientemente he creado 2 plug-in para virtualenvwrapper para hacer esto aut omaticamente Hay uno para joya y NPM:

http://pypi.python.org/pypi/virtualenvwrapper.npm

http://pypi.python.org/pypi/virtualenvwrapper.gem

10

he creado un script bash para automatizar la solución de Natim.

Asegúrese de que su Python virtualenv esté activo y solo ejecute el script. NodeJS, NPM y lessc se descargarán e instalarán en su cuenta virtual.

http://pastebin.com/wKLWgatq

#!/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" 
+0

Si está utilizando buildout, puede echar un vistazo a https://pypi.python.org/pypi/rubygemsrecipe – Natim

+0

Creé una versión de Python: [Descargue e instale nodejs en el virtualenv actual de python] (https: //github.com/wonderbeyond/venvgetnodejs) – wonder

Cuestiones relacionadas