#Python 🐍 – Easy way to install #OpenCV and #TensorFlow in a Virtual Environment in Anaconda . Yes, for drone 🚁 fun !

Hi !

I wrote about this before, however, I never shared the complete set of steps. Here they are.

Install and Update Anaconda

After installing Anaconda, it’s time to update. We need to start Anaconda PowerShell with Administrator privileges.

And then run these commands.

conda update conda 
conda update –all

That was easy.

Create a new Virtual Environment

Virtual Environments are an easy way to have different instances on Python and Anaconda to make tests with different packages, different libraries, etc.

Let’s create a new Virtual Environment named “drone”, and let’s activate /switch to the new virtual environment

conda create -n drone tensorflow 
conda activate drone

Once we activate the new environment, our PowerShell console should add the [drone] prefix. the following image show the change from [base] to [drone].

activate drone virtual environment in the powershell console

Note: Sorry for the crappy interface, new machine and I’m still installing stuff.

Install TensorFlow and OpenCV

The 2 main commands to install the desired packages are

# install TensorFlow
pip install tensorflow --user

# install OpenCV
pip install opencv-python

And that’s it! All the packages should be installed. An easy way to test if both packages are installed is to launch python and

# check tensorflow, and display tensorflow version
import tensorflow as tf

# check OpenCV, and display OpenCV version
import cv2

The output should be similar to this one:

test opencv and tensorflow installed packages
(drone)    bruno@W10-EB18ASUS  C:  WINDOWS  system32 
❯ python -V
Python 3.9.7
(drone)    bruno@W10-EB18ASUS  C:  WINDOWS  system32 
❯ python
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
>>> import cv2
>>> cv2.__version__

Happy coding!


El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:


1 comment

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: