python - 安装tensorflow 2有问题

标签 python tensorflow

我想练习 tensorflow 2,但我尝试在 anaconda 环境中安装它失败。

我的问题是:如何安装 tensorflow 2?如果它可以在 anaconda 环境中完成,在我看来更方便。我不需要理解下面的错误信息,只要我能使用tensorflow 2即可。

  • 首先,我找到了一个用pip安装的,而不是conda

  • 其次,pip 给了我很多错误:每次我感觉我转过一个,另一个就出现了……我认为我做的最好的是(在py36环境): pip install --upgrade --ignore-installed wrapt tensorflow==2.0.0-beta1。 实际上,在卸载 tb-nightly、notebook 和 jupyter 之后,此命令运行时没有明显的错误/警告。但是,python 中的 import tensorflow 给我这个错误:

Traceback (most recent call last):
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _SecKeyCopyExternalRepresentation
  Referenced from: /Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib
  Expected in: /System/Library/Frameworks/Security.framework/Versions/A/Security
 in /Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/Users/steph/anaconda/envs/py36/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): Symbol not found: _SecKeyCopyExternalRepresentation
  Referenced from: /Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib
  Expected in: /System/Library/Frameworks/Security.framework/Versions/A/Security
 in /Users/steph/anaconda/envs/py36/lib/python3.6/site-packages/tensorflow/python/../libtensorflow_framework.2.dylib


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.```

最佳答案

可能你发出了同样的问题here .. 你可以尝试解决升级你的 MacOS 系统的问题 o 尝试在你将用于你的代码的 virtualenv 中安装 tensorflow

编辑:

要在您的虚拟环境(在本例中为 anaconda)中安装包,您需要激活您已经创建的环境(请参阅 anaconda docs 进行制作)并使用

$ conda activate myenv
(myenv) $ pip install tensorflow

关于python - 安装tensorflow 2有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56681399/

相关文章:

python - 未找到模块对象

tensorflow - 是否有相当于 fastai 的 interp.plot_top_losses 的 Tensorflow 或 Keras?

python - 使用 cv2 调整图像大小

python - 在 CPU 上运行 Tensorflow 时抑制 OpenMP 调试消息

python - utcoffset 方法在 datetime 中的作用 - Python

python - 如果我有 PPP 连接,如何通过 python 脚本识别,如果有,打开 LED?

python - 带有外键的 scrapy djangoitem

python - 如何以更优雅的 Pythonic 方式组织此循环

java - 如何确保我的 tensorFlow Java 程序正在 Windows 上使用我的 GPU?

python - 未设置 Tensorflow 恢复权重