import 出错

ERROR:root:Internal Python error in the inspect module.

具体表现为:

ERROR:root:Internal Python error in the inspect module. Below is the traceback from this internal error. ERROR:root:Internal Python error in the inspect module. Below is the traceback from this internal error

Traceback (most recent call last):
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.6156.16\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\program files\Python37\my_flask_env\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\program files\Python37\my_flask_env\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.6156.16\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "D:\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.6156.16\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "D:\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.6156.16\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "D:\program files\Python37\my_flask_env\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.6156.16\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.6156.16\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\program files\Python37\my_flask_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\program files\Python37\my_flask_env\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\program files\Python37\my_flask_env\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors

解决方案:进入提示的网站https://www.tensorflow.org/install/errors,大多数问题都可以在这里找到。这个问题的解决方案在左侧pip中
缺失一个文件
点击上图中的Microsoft VC++ downloads下载安装包并下载,即可成功导入Tensorflow
若无法打开该网站,我这里提供某盘链接The latest supported Visual C++ downloads
提取码:79ws
下载安装之后即可,重新import之后就可以前往下一个坑了。

初学tf尝试

No module named ‘tensorflow.examples.tutorials’

常见于初学者训练mnist

ModuleNotFoundError: No module named 'tensorflow.examples.tutorials'

可先检查tensorflow文件夹中是否存在tutorials文件夹

1、在自己编译器运行的python环境的…\Python3\Lib\site-packages,该目录下有文件夹tensorflow, tensorflow_core, ensorflow_estimator。。。选择进入tensorflow_core\examples文件夹,如果文件夹下只有saved_model这个文件,则是没有tutorials。
在这里插入图片描述
2、前往tensorflow gayhub主页下载总文件夹然后补入缺失文件,GitHub Tensorflow
3、下载解压完毕后,在tensorflow-master\tensorflow\examples\路径下找到tutorials文件夹,把tutorials整个文件夹拷贝到上文中提到的…\Python3\Lib\site-packages\tensorflow_core\examples\中
4、重新import一下,继续踩下一个坑。

当尝试白嫖其他人的代码段时出错

AttributeError: module ‘tensorflow’ has no attribute ‘logging’

AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’

常见于白嫖网上代码段,在tf2下使用了tf1的API

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
tf.logging.set_verbosity(tf.logging.INFO)# 此行直接删除

# 或者替换为
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

重新import,然后继续踩坑

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐