Homebrew is good at everything as a package manager except versioning. By default, only the latest version can be installed, so it takes a lot of effort to go back to the old version. When Python was upgraded to 3.7, there was a problem:

Cannot import tensorflow!!

This is a big deal. Do how? After a long search, I found the answer on Github: the original link

In particular, Python3.7 introduced the reserved word async, which tensorFlow code uses as a variable name. To modify, the method is also simple:

First find the following file: / usr/local/lib/python3.7 / site – packages/tensorflow/python/pywrap_tensorflow_internal py (if using the Anaconda such distribution, Go to the corresponding site-Packages directory (Anaconda has not been upgraded to Python3.7), then search async, replace all with async1, save and close.

[update 11.21] Note that only individual async is being replaced here (please refer to the comments of “Sun cat” students below).

Open IPython to test:

import tensorflow as tf
Copy the code

No problem, it was imported successfully.


Attached: install tensorflow under Python3.7

Since Python3.7 support has not been officially added to TensorFlow, it is not possible to find suitable tensorFlow packages using PIP installation, so install directly from.whL. The specific method is as follows (take Mac as an example) :

PIP install https://download.tensorflow.google.cn/mac/cpu/tensorflow-1.10.0-py3-none-any.whl -- the upgradeCopy the code

If you cannot access this address, please solve it yourself.

Once installed, modify async as described above.