Vorrei installare uno script nodejs (lessc) in un virtualenv.Come installare lessc e nodejs in un virtualenv Python?
Come posso farlo?
Grazie
TmpNR
Vorrei installare uno script nodejs (lessc) in un virtualenv.Come installare lessc e nodejs in un virtualenv Python?
Come posso farlo?
Grazie
TmpNR
mi piace la risposta di shorrty, ha raccomandato utilizzando nodeenv, vedi: is there an virtual environment for node.js?
ho seguito questa guida: http://calvinx.com/2013/07/11/python-virtualenv-with-node-environment-via-nodeenv/
Tutto quello che dovevo fare io 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
Ecco quello che ho usato fino ad ora, ma può essere ottimizzato credo.
Installare 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
Installare NPM (Node Package Manager)
/absolute/path/to/the/virtualenv/bin/activate
curl https://npmjs.org/install.sh | sh
Installare lesscss
npm install less -g
Quando si attiva la vostra virtualenv è possibile utilizzare lessc
Fornirò la mia soluzione generica per lavori con gemme e NPM all'interno di una virtualenv Gems e supporto Npm per essere personalizzato tramite le impostazioni env: GEM_HOME
e npm_config_prefix
Si può bastone il frammento qui sotto nella tua postactivate
o activate
sceneggiatura (è più importa se si utilizza 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
Ora, all'interno del vostro virtualenv tutte le librerie installate con 0.123.o npm -g install
verrà installato nel vostro virtualenv e binari aggiunto nella vostra PATH
se si utilizza virtualenvwrapper
si può fare il cambiamento globale a tutti i vostri virtualenv se si modifica il postactivate
vivere all'interno del vostro $VIRTUALENVWRAPPER_HOOK_DIR
Questa soluzione non coprire installazione nodejs all'interno del virtualenv ma penso che s meglio delegare questo compito al sistema di confezionamento (apt, yum, birra ..) ed installare nodo e NPM globalmente
Edit:
recente ho creato 2 plug-in per virtualenvwrapper per fare questo aut omatically. C'è uno per il gioiello e NPM:
ho creato uno script bash per automatizzare la soluzione di TmpNR.
Assicurati che il tuo virtualenv Python sia attivo ed esegui lo script. NodeJS, NPM e lessc verranno scaricati e installati nel tuo 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"
Potete fornirci alcuni suggerimenti attuali: che cosa è lessc e dove lo si può trovare? Inoltre non capisco come virtualenv e node.js si mescolino: virtualenv è per Python, mentre node.js è una piattaforma basata su JavaScript. – jsalonen
'lessc': http://lesscss.org/ - Virtualenv è per ambiente python e fornisce alcuni eseguibili nell'ambiente, vorrei installare lessc in questo ambiente. – Natim