Adding third party modules to Python

My Anaconda Windows installation did not have an installable package for “torchvision” and “opencv’.  Typically, out of sheer laziness I would just use the Anaconda GUI, switch to my pyTorch environment and search for the missing pieces.  But they were completely missing.

So I had no choice but to launch the Windows “conda” cli that gets installed whenever you do a Windows Anaconda installation. There I switched to my pyTorch conda environment which I had initially created as “Anaconda3”.  I could have called it “pyTorch”, but that would have been a rational choice and where is the fun in that?

I switched to my pyTorch environment using the “activate Anaconda3” command.

Happily I typed at the prompt:

conda install torchvision

And…nothing.  There was no torchvision package for windows.  In fact, all the torchvision packages available were for either Linux or MacOs  It was still not time for the gnashing of teeth, so as a last resort I tried:

pip install torchvision

And that worked. Fortunately, installing the most stable version of OpenCV wasn’t as traumatic:

conda install opencv

…worked without a pip. While in the conda prompt environment just type, python and at the python prompt…

import torchvision

import cv2

to check that things are ok.

SUMMARY:

There are two places to look for Python modules to add to your Anaconda environment:

  • anacoda.org   -> use conda command line to install
  • pypy.org          -> use pip to install

If you can’t find what you are looking for in either one, then it’s time for the gnashing of teeth.

NOTE:

As a “best practices” sort of thing, I am no longer using the Anaconda Navigator GUI for package installations.  Instead, I first look for the packages in anaconda.org and then install the latest version with the conda cli. The versions listed on the Anaconda Navigator GUI may not be the latest one and it might not even warn you.

Fixing Serious Anaconda Problems under Linux

Occasionally  Anaconda either just stops working or it launches applications so slowly that you could literally brew coffee in the time it takes to fire up Spyder.  That’s when radical steps need to be taken and Anaconda needs to be reinstalled.  Of course, you will have to reinstall pytorch and torchvision, but it’s that doesn’t take long.

Before you uninstall  Anaconda, you must completely get rid of it’s files:

  1. The main folder usually called “anaconda3”.  This is visible.
  2. The two hidden folders .conda and .anaconda

While you’re at it, download the excellent Conda Cheat Sheet:

https://conda.io/docs/_downloads/conda-cheatsheet.pdf