I am trying to install tensorflow (with or without GPU support) with the keras API in the QGIS 3.4 LTR python 3 environment but without success. I do have a working install of tensorflow-gpu that I use in anaconda. I also have a working install of scikit-learn (and others) in the QGIS 3 env. So I think my method using the OSgeo4 shell and pip seems mostly OK. So from the python console in QGIS I can type:

import sklearn

And that works fine. But the same thing is not true for tensorflow and keras. First I tried to install tensorflow-gpu, when using pip I got no error messages. But:

import tensorflow as tf

returns this error:

ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive

I have used Settings>options>System and added all the CUDA paths to my environment variables. These do point to the folder where cudart64_100.dll is found.

If I un-install tensorflow-gpu and downgrade to the cpu version, I get another problem after an attempted import:

AttributeError: type object 'h5py.h5.H5PYConfig' has no attribute '__reduce_cython__'

This seems to be related to v 2.10 of h5py.

Ultimately, is there a solution here? Is it even possible to install tensorflow in QGIS and use it directly from the PyQGIS console?

  • I have made progress and am now running my code with tensorflow, non-GPU. The solution was to downgrade h5py to v 2.9. But the environment path bug for tensorflow-gpu and CUDA tools persists. – Patrice Carbonneau Oct 31 '19 at 9:13

Solved my problem. For reference:

1- pip install tensorflow-gpu in the Python 3.7 env of QGIS, be sure to use the py3_env command.

2-Be sure h5py is v2.9. I had to force this. This will prevent tensorflow bugs and QGIS crashes

3- In QGIS, use Settings>Options>System. Tick 'use custom variables'

4- Pulldown the small menu to Append

5- enter PATH as the variable

6- Find the location of your CUDA folder and the ...\bin and the ...\libnvvp paths

7- add these paths with a ; separator as the value of the PATH variable.

This will give you a working install of TF GPU that can be called from the QGIS python console!

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.