I am working on my project and using a raspberry pi 2 with raspbian OS. I followed the following link http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie/ to install opencv and python on my pi. What I am trying to do is I want to activate my virtual environment automatically when the pi boots up and want to run a particular .py file on startup. What I have done so far is:

(i) I have created a .sh file and edited it as follows:

  # launcher.sh
  # navigate to home directory, then to this directory, then execute python script, then back home
  cd /
  cd home/pi/
  sudo source ~/.profile          (sourcing .profile)
  sudo workon cv                  (cv is my virtual environment)
  sudo python test_video.py       (test_video.py is .py file)
  cd /

(ii) To make it executable, I used the following command:

   chmod 755 launcher.sh

(iii) Then I tried launching my file using

   sh launcher.sh (launcher is filename)

When I ran this, I got the following errors:

   sudo: source: command not found
   sudo: workon: command not found
   Traceback (most recent call last):
   File "test_video.py", line 4, in <module>
          import cv2
   ImportError: No module named cv2

Kindly help me out. I am trying to automatically activate my virtual environemt name 'cv' and want to run test_video.py file on startup.


You have three problems there: 1) you'll need to supply the full path to source 2) you'll need to supply the full path to workon 3) there's an error in line 4 of test_video.py (my best guess is that cv2 hasn't been installed (apt-get install ...)

I'm quite surprised the shell script ran: my experience was that I needed to supply the full path to the shell script. Simply typing its name from the same folder was insufficient.

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.