M1 Mac 上的 TensorFlow(任何版本 > 2.5.0):PyCharm 中没有代码补全

发布于 2025-01-09 11:16:48 字数 978 浏览 3 评论 0原文

我正在使用 JetBrain 的 PyCharm IDE 在 M1 Mac 计算机上与 TensorFlow 配合使用。 我已按照给定顺序使用以下命令安装了 TensorFlow:

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

对于安装 Conda,我遵循 Apple 官方 文档

我可以毫无问题地导入 TensorFlow;它打印的版本号是2.8.0。 但是,我没有收到任何代码完成建议。 输入tensorflow.keras.l时,它应该建议layerslosses。 正如所附的屏幕截图所示,我没有得到任何可用的东西: 输入图片这里的描述

我已经重新启动了IDE,使所有缓存失效,重新索引项目,并从头开始重新创建环境多次,但都无济于事。其他建议按预期工作(例如屏幕截图中的 os.path.join 行)。让我困惑的是,在同一台机器(M1 Mac)上的另一个项目中,我使用 TensorFlow 2.5.0,它为我提供了所需的代码建议。

由于无法获取最新 TensorFlow 版本的代码建议,我无法更新到版本 2.8.0。您对解决这个问题有什么建议?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2025-01-16 11:16:48

对于代码补全,您可以按照以下解决方法进行操作。

from tensorflow import keras

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

有关更多详细信息,请参阅此处

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文