2

I'm trying to install OpenCV in my raspberry (I'm new with it) and I followed this post. I have done all the steps from 0 to 6.

All this installation it's done in a virtual environment, but now I don't know how to activate this environment. The post says that I have to introduce this line workon OpenCV-3.4.4-py3 but as @Heath Raftery and @Shreyas Murali say the correct line is workoncv-3.4.4 OpenCV-3.4.4-py3 because in the step 3 we do

echo "alias workoncv-$cvVersion=\"source $cwd/OpenCV-$cvVersion-py3/bin/activate\"" >> ~/.bashrc

I tried to execute workoncv-3.4.4 OpenCV-3.4.4-py3 in the folder "OpenCV-3.4.4-py3" but it fails and appear the following error message

bash: workon: command not found

I'm pretty sure it's a stupid question but I'm really lost with it.

How can I activate the virtual environment?

¡Salud!

Lleims
  • 210
  • 1
  • 3
  • 13

2 Answers2

1

relevant sections from that post go like so:

step 0: defines the opencv version

echo "OpenCV installation by learnOpenCV.com"
cvVersion="3.4.4"

step 3: sets up an alias

# Install virtual environment
python3 -m venv OpenCV-"$cvVersion"-py3
echo "# Virtual Environment Wrapper" >> ~/.bashrc
echo "alias workoncv-$cvVersion=\"source $cwd/OpenCV-$cvVersion-py3/bin/activate\"" >> ~/.bashrc
source "$cwd"/OpenCV-"$cvVersion"-py3/bin/activate
#############

The alias would expand to workoncv-3.4.4 and not just the suffix workon

Given the alias uses $cwd, you need to navigate to the parent folder that contains the virtual env folder OpenCV-3.4.4-py3 before executing the alias

Shreyas Murali
  • 2,446
  • 1
  • 16
  • 23
1

When you executed this line in step 3:

echo "alias workoncv-$cvVersion=\"source $cwd/OpenCV-$cvVersion-py3/bin/activate\"" >> ~/.bashrc

It should have added a line to the end of your ~/.bashrc file. The line should look something like:

alias workoncv-3.4.4="source /your/working/path/OpenCV-3.4.4-py3/bin/activate"

First make sure that line exists by executing less ~/.bashrc and scrolling to the end of the file (hit q to exit), then log out and log back in to ensure the line takes effect.

Now you can just type workoncv-3.4.4 at the command line at any time to activate the venv.

Heath Raftery
  • 275
  • 1
  • 9