I am working on my project and using a raspberry pi 3B+ with raspbian OS. I followed the following link to pip install open cv on my pi using a virtual environment I named 'cv' and it works fine: https://www.pyimagesearch.com/2018/09/19/pip-install-opencv/

What I am trying to do is I want to activate my virtual environment and to run a particular .py (timer_design) file from a .sh (my_command) file so that I can execute it from a desktop icon for people to use. What I have done so far is:

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

cd /home/pi
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
. /usr/local/bin/virtualenvwrapper.sh
workon cv
sudo python timer_design.py

(ii) To make virtualenvwrapper.sh executable, I used the following command:

sudo chmod 777 virtualenvwrapper.sh

(iii) Then I made my my_command executable from within my file from my home directory and ran it using this command:


When I ran this, I got the following errors:

./my_command: 110: /usr/local/bin/virtualenvwrapper.sh: function: not found
./my_command: 120: /usr/local/bin/virtualenvwrapper.sh: Syntax error: "}" unexpected

everything works fine when I run the following commands straight into terminal:

$source ~/.profile
$workon cv
$python timer_design.py

please help :)

Your Answer

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

Browse other questions tagged or ask your own question.