I am trying to install opencv 4 on my raspberry pi 4 using these instructions from this website but I have come across an error when I run the command mkvirtualenv cv -p python3.
The error is found below. Please do help me guys as I have searched on google and tried this soltuion mentioned but it still gives me the error message.

pi@raspberrypi:~ $ mkvirtualenv cv -p python3
created virtual environment CPython3.7.3.final.0-32 in 451ms
  creator CPython3Posix(dest=/home/pi/.virtualenvs/cv, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/home/pi/.local/share/virtualenv/seed-v1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /home/pi/.virtualenvs/cv/usr/local/bin/predeactivate
ERROR: Environment '/home/pi/.virtualenvs/cv' does not contain an activate script.

3 Answers 3


I'm running on a raspbian buster with Python 3.7.3. I ran into the same issue, "ERROR...no activation script". I tried @Lombax answer but it didn't work.

However, I noticed that the version of virtualenvwrapper I had installed was 5.0.0. I checked on PyPi and it's still at version 4.8.4. So I uninstalled virtualenv and virtualenvwrapper: sudo pip3 uninstall virtualenv virtualenvwrapper.

Then I reinstalled both and specified the version: sudo pip3 install virtualenv virtualenvwrapper=='4.8.4' I sourced my .bashrc, in which I had appended the settings:

export PATH=/usr/local/bin:$PATH
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

And now mkvirtualenv test works. Not sure what's the bug with version 5.x of virtualenvwrapper, in the meantime, this got around the problem for me, hope this helps.


I am also facing the same error. You must add these lines on ~/.profile

export WORKON_HOME=$HOME/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv source /usr/local/bin/virtualenvwrapper.sh export VIRTUALENVWRAPPER_ENV_BIN_DIR=bin

  • The last line here (export VIRTUALENVWRAPPER_ENV_BIN_DIR=bin) is what was missing and what made the error go away for me. That line is also missing from the how-to I used at qengineering.eu/install-opencv-4.3-on-raspberry-pi-4.html
    – RealHandy
    Jul 14, 2020 at 17:59
  • export VIRTUALENVWRAPPER_ENV_BIN_DIR=local/bin in my case. Just set the variable to the folder of your bin directory considering the directory of your environment as a root.
    – Victor Di
    Mar 3, 2023 at 15:13

I am using pyenv instead and it is working well. There is an excellent article by ReadPython on how to use it.

I updated my environment with the tools suggested in the article.

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

Then I installed pyenv and updated my .bashrc.

I decided to install Python 3.8.2 for use with CV. This takes a little while to compile.

Then I created a virtual environment:

pyenv virtualenv 3.8.2 cv

Next, I created a directory called cv to do my work in.

Finally, I enabled the virtual environment by cd'ing into cv and then used the following command:

pyenv virtualenv 3.8.2 cv

Now when I cd into the cv directory I am in a virtual environment using Python 3.8.2 and when I exit that directory I am no longer in a virtual environment and back to using Python 3.7.2.

Activation is automatic.

  • Solving the virtualenv problem, I was not able to succssfully compile the code nor install from pip. Oh well, going to the image provided by Adrian. Feb 27, 2020 at 19:16

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