I'm writing a shell script to set up my virtual env environment and install all related python packages via pip.
virtualenv -q -p /usr/bin/python3.5 $1
/bin/bash $1/bin/activate
pip install -r requirements.txt
$1 is the name of the virtualenv. The problem I have is that the pip command does not work in my virtualenv but is executed globally instead.
As I mean to know you have to activate the virtualenv with:
source activate
I am not sure if this can be done from within a shell script, but you can try it as follows:
virtualenv -q -p /usr/bin/python3.5 $1
source $1/bin/activate
$1/bin/pip install -r requirements.txt
# pip install -r requirements.txt
Excerpt from activate:
$ cat activate
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
Looks like you've found the solution to your problem, but for future reference, you don't need to activate the virtualenv in order to run pip inside it:
#!/bin/bash
virtualenv -q -p /usr/bin/python3.5 $1
$1/bin/pip install -r requirements.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With