You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

先导入pandas再导入TensorFlow导致脚本冻结问题求助

Pandas与TensorFlow导入顺序引发脚本冻结问题

环境:Apple M3 Pro(36GB)+ macOS Sonoma 14.5,从Windows切换至此设备后出现异常:

  • 当先导入pandas再导入TensorFlow/Keras时,脚本会无响应冻结
  • 调换导入顺序(先TensorFlow后pandas)则可正常运行,即使脚本中并未实际使用pandas也存在该问题

测试脚本

import numpy as np
import os
import pandas as pd
from tensorflow.keras import layers, models

print("Creating simple model...")
try:
    model = models.Sequential([
        layers.Input(shape=(10,)),
        layers.Dense(64, activation='relu'),
        layers.Dense(1, activation='linear')
    ])
    print("Model created successfully.")
except Exception as e:
    print(f"Error creating model: {e}")

x_train = np.random.rand(100, 10)
y_train = np.random.rand(100, 1)

# Compile the model
model.compile(optimizer='adam', loss='mean_squared_error')

# Train the model
try:
    model.fit(x_train, y_train, epochs=5, batch_size=32)
    print("Model training completed successfully.")
except Exception as e:
    print(f"Error during training: {e}")

运行现象

  • 执行上述脚本时,输出到TensorFlow设备创建信息后即冻结,需手动终止进程
  • 调换导入顺序后,模型创建与训练可顺利完成
  • 经细化调试,冻结点转移至model.fit阶段,但问题仍未解决;全程无任何异常抛出,即使单独为导入语句添加异常捕获也无法捕获错误

当前环境依赖版本

Package                      Version
---------------------------- -----------
absl-py                      2.1.0
astunparse                   1.6.3
Bottleneck                   1.3.7
cachetools                   5.3.3
certifi                      2024.2.2
charset-normalizer           3.3.2
db-dtypes                    1.2.0
flatbuffers                  24.3.25
gast                         0.5.4
google-api-core              2.19.0
google-auth                  2.29.0
google-cloud-bigquery        3.23.1
google-cloud-core            2.4.1
google-crc32c                1.5.0
google-pasta                 0.2.0
google-resumable-media       2.7.0
googleapis-common-protos     1.63.0
grpcio                       1.64.0
grpcio-status                1.62.2
h5py                         3.11.0
idna                         3.7
importlib_metadata           7.1.0
joblib                       1.4.2
keras                        3.3.3
libclang                     18.1.1
Markdown                     3.6
markdown-it-py               3.0.0
MarkupSafe                   2.1.5
mdurl                        0.1.2
ml-dtypes                    0.3.2
namex                        0.0.8
numexpr                      2.8.7
numpy                        1.26.4
opt-einsum                   3.3.0
optree                       0.11.0
packaging                    24.0
pandas                       2.2.1
pip                          24.0
proto-plus                   1.23.0
protobuf                     4.25.3
pyarrow                      16.1.0
pyasn1                       0.6.0
pyasn1_modules               0.4.0
Pygments                     2.18.0
python-dateutil              2.9.0.post0
pytz                         2024.1
requests                     2.32.3
rich                         13.7.1
rsa                          4.9
scikit-learn                 1.4.2
scipy                        1.11.4
setuptools                   69.5.1
six                          1.16.0
tensorboard                  2.16.2
tensorboard-data-server      0.7.2
tensorflow                   2.16.1
tensorflow-io-gcs-filesystem 0.37.0
tensorflow-macos             2.16.1
tensorflow-metal             1.1.0
termcolor                    2.4.0
threadpoolctl                3.5.0
tqdm                         4.66.4
typing_extensions            4.12.0
tzdata                       2024.1
urllib3                      2.2.1
Werkzeug                     3.0.3
wheel                        0.43.0
wrapt                        1.16.0
zipp                         3.19.0

内容的提问来源于stack exchange,提问作者Ilhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 03:44:52