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!
2 Answers 2
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 directoryOpenCV-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 youLleims– Lleims2019年04月27日 06:39:43 +00:00Commented Apr 27, 2019 at 6:39
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 directoryOpenCV-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 youLleims– Lleims2019年04月27日 06:38:41 +00:00Commented Apr 27, 2019 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 executingworkon
, which results in the errorworkon: command not found
, as expected, becauseworkon
doesn't exist, onlyworkoncv-3.4.4
. Try executingalias
. It should listworkoncv-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 correspondingactivate
script. Maybe the issue is there, but that's not the question you've asked.Heath Raftery– Heath Raftery2019年04月27日 06:51:03 +00:00Commented Apr 27, 2019 at 6:51 -
I am executing
workoncv-3.4.4
and says the same error, and inalias
don`t appears anything about workonLleims– Lleims2019年04月27日 06:56:55 +00:00Commented Apr 27, 2019 at 6:56 -
1I 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– Heath Raftery2019年04月27日 08:36:54 +00:00Commented Apr 27, 2019 at 8:36 -
1Much 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– Heath Raftery2019年04月29日 00:08:12 +00:00Commented Apr 29, 2019 at 0:08
python
.