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!

4

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

  • 1
    I wish you had said a little bit more about the solution... – Julien L Jun 15 '18 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.