Skip to main content
 首页 » 编程设计

python之安装tensorflow 2有问题

2024年11月24日26arxive

我想练习 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