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!

  • a better tag for the question would be python. – Shreyas Murali Apr 26 at 18:42
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

  • As I said to Heath Raftery, I am trying to execute the comand workoncv-3.4.4 in the directory OpenCV-3.4.4-py3 and says the same error. Maybe I forget to do that echo, I think I would do all the installation again and ensure I do this step. Thank you – NEA Apr 27 at 6:39
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.

  • I am trying to execute the comand workoncv-3.4.4 in the directory OpenCV-3.4.4-py3 and says the same error. Maybe I forget to do that echo, I think I would do all the installation again and ensure I do this step. Thank you – NEA Apr 27 at 6:38
  • It doesn't matter which directory you do it in. Are you sure you're executing workoncv-3.4.4 without any spaces? In your original post you say you're executing workon, which results in the error workon: command not found, as expected, because workon doesn't exist, only workoncv-3.4.4. Try executing alias. It should list workoncv-3.4.4 as one of your aliases. Does it? And is that what you're executing? If so, you need to look deeper at what's in the corresponding activate script. Maybe the issue is there, but that's not the question you've asked. – Heath Raftery Apr 27 at 6:51
  • I am executing workoncv-3.4.4 and says the same error, and in aliasdon`t appears anything about workon – NEA Apr 27 at 6:56
  • 1
    I hope you mean less ~/.bashrc. Okay, great, that means you didn't successfully follow Step 0 in the instructions in the original post you linked (cvVersion is not defined). Start again, and follow the instructions very carefully. Post a question or do some Googling as soon as you something doesn't seem to work right. – Heath Raftery Apr 27 at 8:36
  • 1
    Much better! Please update your question and we'll delete all this and have another go. Remember to specify exactly what you typed and exactly what the output is. – Heath Raftery Apr 29 at 0:08

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.