Can’t install Tensorflow Mac

Posted on

Question :

Can’t install Tensorflow Mac

I checked my pip3 & python3 version:

  (tensorflow) MacBook-Pro-de-Hector-2:tensorflow hectoresteban$ pip3 -V
    pip 10.0.1 from /Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip (python 3.7)

(tensorflow) MacBook-Pro-de-Hector-2:tensorflow hectoresteban$ python3 -V
Python 3.7.0

In the virtual environment I am currently using I did:

pip3 install --upgrade

As the standard way pip3 install tensorflow output the following message:

could not find a version that satisfies the requirement tensorflow (from versions: )

After installed using the first method explained:

(tensorflow) MacBook-Pro-de-Hector-2:tensorflow hectoresteban$ python3
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/python/", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/python/", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Users/hectoresteban/.virtualenvs/tensorflow/lib/python3.7/site-packages/tensorflow/python/", line 114
    def TFE_ContextOptionsSetAsync(arg1, async):
SyntaxError: invalid syntax

What is the issue? I can download other packages such as numpy but no Tensorflow. (MacOS 10.13.4)

Answer #1:

Update: version 1.13 introduces Python 3.7 support

The recent release candidate for the 1.13 version brings Python 3.7 support, in particular precompiled CPU wheels are also available for MacOS 10.11 and newer (link to 1.13.1). Install as usual:

$ pip install tensorflow>=1.13

Original answer (outdated)

tensorflow does not support Python 3.7 at the moment. The reason for this is that:

  • tensorflow uses async as function parameter name, and async and await became reserved keywords in Python 3.7 (as pointed by @phd in this comment) – this is why you’re getting the import error;

  • Python 3.7 changed the return type of PyUnicode_AsUTF8AndSize function in the C API used by tensorflow:

    Changed in version 3.7: The return type is now const char * rather of char *.

This means both issues must be fixed before tensorflow can be built and released for Python 3.7 & Linux/MacOS. You can track the current status here: issue #20517.

The solution hence would be avoiding Python 3.7 if you need to continue working with tensorflow. Stick with Python 3.6 for the time being.

If you are willing to build tensorflow from source: There is a patch proposed to fix both issues. If you want to try it out, follow the Install TensorFlow from Sources tutorial from the official docs, the only difference being on the beginning:

  1. Clone the repository

    $ git clone
  2. Copy the patch contents to a file, e.g. tf.patch

  3. Apply the patch:

    $ git apply tf.patch
  4. Proceed with the rest of the tutorial.

Also note that you will have to build the latest protobuf, as the support for Python 3.7 was added to it lately, but is not contained in any released version. Edit tensorflow/contrib/cmake/external/protobuf.cmake to point to the current HEAD of the protobuf repo.

Answered By: hoefling

Answer #2:

I tried this command on macOS Catalina (Python 3.6) and it ran properly:

$ python3 -m pip install –upgrade

Answered By: George Dimitriou

Leave a Reply

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