Tensorflow2错误踩坑

ModuleNotFoundError: No module named 'tensorflow'

注意一下,确定你在跑脚本时候的python版本,假如是mac用户,由于mac本身自带低版本的python,所以python xxx.py默认是python2.x的版本,而正确的应该是根据你安装虚拟环境时候选择的python编译版本来,假如是python3,就用python3 xxx.py来执行

AttributeError: module 'tensorflow' has no attribute 'Session'

假如你是tensorflow2.x的,tf.Session()已经在2.0被废弃了, 请把hello world换成以下的内容,在2.0中已经可以直接使用print来打出constant内容。

import tensorflow as tf
msg = tf.constant('TensorFlow 2.0 Hello World')
tf.print(msg)

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate

假如你用了virtualenv,请在 env/lib/python3.x/site-packages/tensorflow_core/python/keras/utils/data_utils.py的导入语句下加入以下代码片段,

import requests
requests.packages.urllib3.disable_warnings()
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context

未完待续....

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。