【发布时间】:2021-02-22 11:47:48
【问题描述】:
为了了解深度学习和神经网络,我正在尝试使用conda 4.9.1(最初包含Python 3.8.3)在我的笔记本电脑(Dell Inspiron 5559、4GB RAM、Windows 10)上安装 Tensorflow。为此,我使用了以下命令:
conda create -n tf tensorflow
这成功运行并安装了Python 3.7.9、tensorflow 2.1.0 和许多其他模块。现在我想测试它是否有效,所以在 Python 终端中,导入了一些模块。 math 和 numpy 的导入成功。但是当我导入 tensorflow 时,该过程失败并显示以下内容:
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 101, in
<module> from tensorflow_core import *
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow_core\__init__.py", line 40, in
<module> from tensorflow.python.tools import module_util as _module_util
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 959, in _find_and_load_unlocked
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 50, in
__getattr__ module = self._load()
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "D:\Program Files\Anaconda3\envs\tf\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow_core\python\__init__.py", line
49, in <module> from tensorflow.python import pywrap_tensorflow
File "D:\Program Files\Anaconda3\envs\tf\lib\site-
packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\Program Files\Anaconda3\envs\tf\lib\site-
packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\Program Files\Anaconda3\envs\tf\lib\site-
packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 15, in swig_import_helper
import imp
ValueError: source code string cannot contain null bytes
即使我运行导入 Tensorflow 的程序也会出现此错误。
我查看了大多数其他教程,似乎没有人遇到这个错误。我也尝试使用较低版本的 Python 和 Tensorflow,但出现同样的错误。
谁能找到正在发生的事情,我该怎么办?
【问题讨论】:
-
我想我曾经遇到过这个问题(虽然使用 tensorflow v1)。我不记得具体细节,但我记得我必须从源代码安装 tensorflow。你用的是什么操作系统?
-
@JosephBudin 我使用的是 Windows 10
标签: python python-3.x tensorflow anaconda conda