How to install Tensorflow in an Anaconda virtual environment – Mac

So I have Anaconda installed and wanted to install TensorFlow as well (I’m using PyCharm):

I tried installing TensorFlow with Conda as per official doc:
https://www.tensorflow.org/install/install_mac#installing_with_anaconda

  • conda create -n tensorflow pip python=3.6
  • source activate tensorflow
  • pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl

However when creating a new virtual environment in PyCharm you need to make sure TensorFlow is installed as well in there, to do so simple do (after you have created your project {i.e. tf_basics} in PyCharm):

  • source activate tf_basics
  • pip install –ignore-installed –upgrade $URL_THAT_MAKES_SENSE I used:
    • pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl
    • Tip: you may get annoying messages like: “Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA”
    • Installing the proper tf version should fix it, take a look here for more info: https://github.com/lakshayg/tensorflow-build
    • Or just do…
      import os
      os.environ[‘TF_CPP_MIN_LOG_LEVEL’] = ‘2’

To test your virtual env is running TensorFlow you can run TensorFlow hello world:

import tensorflow as tf
hello = tf.constant(‘Hello, TensorFlow!’)
sess = tf.Session()
print(sess.run(hello))

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *