module' object has no attribute 'urlretrieve'

本文详细解析了从Python2升级到Python3时遇到的常见错误:'module' object has no attribute 'urlretrieve'。阐述了Python3中urllib模块的变化,以及如何正确导入和使用urlretrieve函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python27的程序在python33中调试时出现:‘module’ object has no attribute ‘urlretrieve’,的错误。

-- encoding:UTF-8 --

import urllib.request

url = r’https://www.google.com.hk/intl/zh-CN/images/logo_cn.png
path = r’c:/img/logo_cn.png’
data = urllib.request.urlretrieve( url, path )

‘module’ object has no attribute ‘urlretrieve’?
在 python3中,urllib 被拆分成三个 modules request, response, 和 error。如果你在 Python2 中使用 import urllib 和 import urllib2,则在 Python3 中,要用 import urllib.request import urllib.response import urllib.error 代替

2025-06-23 14:58:05.426819: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-06-23 14:58:06.523258: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. [14:58:07] 程序启动 2025-06-23 14:58:07.945195: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Traceback (most recent call last): File "E:\pycharm\study\object\face_model.py", line 366, in <module> main() File "E:\pycharm\study\object\face_model.py", line 316, in main recognizer = DormFaceRecognizer( File "E:\pycharm\study\object\face_model.py", line 118, in __init__ self.embedder = load_facenet_manually(cache_dir=facenet_cache_dir) File "E:\pycharm\study\object\face_model.py", line 52, in load_facenet_manually socket.setdefaulttimeout(60) # 60秒超时 AttributeError: type object 'socket' has no attribute 'setdefaulttimeout' 正在初始化FaceNet... 发现已缓存的模型文件: ./facenet_cache\facenet_weights.h5 文件大小可能不完整(87.92MB),将重新下载... 正在下载FaceNet模型文件(约95MB)...
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值