5

I am trying to start a python script that exists in a virtualenv from bootup on my RPi. From reading this post and the RPi rc.local post I know that I will have to add something like this to /etc/rc.local to start the script:

python /home/pi/myscript.py 

My question is how to activate the virtualenv that myscript.py depends on? The name on my virtualenv is cv3. This is what my ~/.profile contains:

# virtualenv and virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

From what I read in this post I tried to activate the virtualenv by calling

cd /usr/local/bin/
source cv3/bin/activate

and then

cd /usr/local/bin/
source bin/activate

Neither of which worked so then I tried to implement the same code I use to activate the virtualenv manually which is cd'ing into my project directory, sourcing the profile and then calling workon cv3 as follows:

cd /my/project/folder
source ~/.profile
workon cv3

None of these solutions worked for me. Can someone please tell me how a virtualenv is activated from rc.local on a linux machine? I am running Noobs Raspbian on my RPi.

I would greatly appreciate any direction or advice you could offer. Thank you!

hlupico
  • 91
  • 1
  • 1
  • 4

1 Answers1

4

Using '. home/pi/.virtualenvs/cv3/bin/activate' to activate the virtualenv worked!

hlupico
  • 91
  • 1
  • 1
  • 4