Skip to content
Advertisement

TensorFlow (any version > 2.5.0) on M1 Mac: No code completion in PyCharm

I am using JetBrain’s PyCharm IDE to work with TensorFlow on a M1 Mac machine. I have installed TensorFlow using the following commands in the given order:

conda create -n data-science -y python=3.9
conda activate data-science
conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal

For installing Conda, I followed Apple’s official documentation

I can import TensorFlow without problems; the version number it prints is 2.8.0. However, I am not getting any code completion suggestions. When typing tensorflow.keras.l, it should suggest layers, or losses. As the attached screenshot shows, I am not getting anything usable: enter image description here

I have restarted the IDE, invalidated any caches, re-indexed the project, and re-created the environment from scratch multiple times, all to no avail. Other suggestions are working as expected (such as the os.path.join line in the screenshot). What puzzles me is that, in another project on the very same machine (M1 Mac), I am using TensorFlow 2.5.0, which gives me the desired code suggestions.

The inability to get code suggestion for more recent TensorFlow versions has stopped me from updating to, e.g., version 2.8.0. What are your suggestions to solve this issue?

Advertisement

Answer

For code completion you can follow below workaround

from tensorflow import keras

if typing.TYPE_CHECKING:
    from keras.api._v2 import keras

For more details please refer here.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement