编辑:在某些Windows版本中,这似乎是一个问题。我在Linux OS上尝试了同样的方法,终于奏效了。
在我的虚拟环境中,我安装了tensorflow。然后尝试将其导入python,但导入错误。
我已经尝试了Internet上所有可用的黑客手段,但似乎没有一个对我有用。请帮忙。
基本导入命令
E:\tensor1>myenv\Scripts\activate.bat
(myenv) E:\tensor1>python
>>> import tensorflow
无论我尝试什么,都会无情地显示此错误:
Traceback (most recent call last):
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow.p
y", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow_i
nternal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow_i
nternal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\samiam\AppData\Local\Programs\Python\Python37\lib\imp.py", line
242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\samiam\AppData\Local\Programs\Python\Python37\lib\imp.py", line
342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\tensor1\myenv\lib\site-packages\tensorflow\__init__.py", line 28, in
<module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\__init__.py", line
49, in <module>
from tensorflow.python import pywrap_tensorflow
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow.p
y", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow.p
y", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow_i
nternal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "E:\tensor1\myenv\lib\site-packages\tensorflow\python\pywrap_tensorflow_i
nternal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\samiam\AppData\Local\Programs\Python\Python37\lib\imp.py", line
242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\samiam\AppData\Local\Programs\Python\Python37\lib\imp.py", line
342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
Failed to load the native TensorFlow runtime.