Solution 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 https://github.com/tensorflow/tensorflow
    
  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.

Solution 2:

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

$ python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl