#Anaconda – My steps to install a virtual environment with #TensorFlow, #Keras and more

Hi!

So today post is not a post, just a selfish reminder of the steps I do when I setup a new dev machine

  • Install Anaconda (see references). I use the default settings, and important: I don’t add Anaconda to Windows PATH.
  • Open Anaconda command prompt as administrator
open anaconda as administrator

Need to be open as Admin in order to install updates

  • Install updates with the command
conda update conda 
conda update –all
  • Create a new development environment named “tfEnv” with tensorflow. Activate the environment
conda create -n tfenv tensorflow 
conda activate tfenv
  • The command to install keras is
pip install
keras

However, if it doesn’t work, I install keras with the following packages

pip install matplotlib 
pip install pillow
pip install tensorflow==1.14
conda install mingw libpython
pip install git+git://github.com/Theano/Theano.git
pip install git+git://github.com/fchollet/keras.git
  • Finally, install Jupyter notebook kernel and create a new kernel for the current virtual environment
pip install ipykernel 
ipython kernel install --user --name=tfEnv
  • There seems to be an issue to install OpenCV using pip with the command
pip install
opencv-python

So, I Install the OpenCV nonofficial package. 1st I download a compatible package from

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl

Install with

pip install
c:\temp\opencv_python-4.1.1-cp36-cp36m-win_amd64.whl

Happy coding!

Greetings @ Toronto

El Bruno

References

Advertisements

#Anaconda – How to create a custom #Python virtual environment and use it in #Jupyter notebooks (a kernel!)

Hi!

In yesterday post, I created a new virtual environment named [devtf] and in this environment I’ve installed a lot of tools that I need. Then I tried to launch a jupyter notebook from this environment, to use this tools and, of course, it didn’t work.

anaconda start virtual environment and error on launch jupyter notebook

It was time to read and learn how this works. So, when I finally get this I find this amazing article which really explain how this works “Using Virtual Environments in Jupyter Notebook and Python” (see references)

Jupyter Notebook makes sure that the IPython kernel is available, but you have to manually add a kernel with a different version of Python or a virtual environment. First, you need to activate your virtual environment. Next, install ipykernel which provides the IPython kernel for Jupyter. And finally, you can add your virtual environment to Jupyter.

So the commands are

pip install --user ipykernel 
python -m ipykernel install --user --name=devtf

Where “devtf” is the name of the new kernel you want to create. Now, when I launch Jupyter Notebooks, the new kernel is available to be used

jupyter notebook change kernel to one with tensorflow

When I started to use this new kernel (virtual environment) I realized that I didn’t installed TensorFlow. You know, being happy about this, naming the kernel TF but not installing the core component. And, sure, my notebooks didn’t work.

jupyter notebook with kernel without tensorflow

I went to my terminal / command prompt and installed TensorFlow. Then I only need to restart the Kernel, and everything start working. I added a extra couple of lines in my notebook just to check the TensorFlow and keras versions.

jupyter notebook tf ok and test keras version

I find similar errors with another packages, so I pip installed the packages in the terminal and restart the kernel to have the notebook OK. So, my simple reminder for myself about how to do this!

Happy coding!

Greetings @ Mississauga

El Bruno

References

#Python – Can’t install TensorFlow on Anaconda, maybe is the Visual Studio distribution

Hi!

This is the 2nd time I get a weird error when I install TensorFlow in my Anaconda distribution. And this is the 2nd time I realize that I’m using the Anaconda version that is preinstalled with Visual Studio. I’m not sure if the spaces in the path affects the creation of environments or it’s something else, however my current and big and amazing solution is:

  • Uninstall Anaconda
  • Install Anaconda again

And then, follow the simple commands in the official Anaconda and TensorFlow doc (see references)

conda create -n tensorflow_env tensorflow
conda activate tensorflow_env

Once tensorflow is installed, I usually test this in python

> Python 
import tensorflow as tf
print(tf.__version__)

Note: please ignore the typos!

anaconda start python and test anaconda version

Now TensorFlow is installed and it’s time to move forward with a new development environment.

Happy Coding!

Greetings @ Burlington

El Bruno

References

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python

Hi !

I’ve write a lot about how to use AI models in C# to perform tasks like Face recognition, speech analysis, and more. During the Chicago CodeCamp, someone ask me about how to perform Face Recognition in Python. I didn’t have any working sample to showcase this, and I failed in try to write a 2 min app. So I added this into my ToDo list.

For this demo I’ll use Anaconda as the base Python distribution and Visual Studio Code as the code editor. There are several packages to perform face detection in Python. I’ll use a mix between OpenCV and Adam Geitgey Face Recognition package to use the camera and detect and recognize faces.

I’ll start by installing some packages to use in python app: dlib, openCV and face_recognition

"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install dlib --user  

"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install face_recognition --user

"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install opencv-python --user  

And, the first step will be to detect faces and draw frames around them. All of this in 20 lines of code

When we run the app, we will see the camera feed and frames around the detected faces. In my next post I’ll add some extra code to perform face recognition.

Happy Coding!

Greetings @ Toronto

El Bruno

Resources