Python 2.7.3 AttributeError: 'module' object has no attribute 'urlopen'
2017-08-07 08:00
1156 查看
在使用下面语句时候出现
from urllib import urlopen
webpage = urlopen('http://www.python.org')
AttributeError: 'module' object has no attribute'urlopen'
我是ubuntu 12.04 + 自带Python 2,7.3
一开始以为是什么Python和Python3不兼容导致,然后在urllib2、urllib还有什么urllib2.request一直反复折腾。。。。
后来stackoverflow一下,发现时urllib.pyc文件不对导致,需要重新编译生成一个该文件。
具体pyc文件是啥就不说了,自行百度。
下面说下我的解决过程:
1、找到urllib.pyc文件路径,并进入该路径
2、用sudo删除该文件
3、但是compile编译重新生成.pyc文件,报错:IOError: [Errno 13] Permission denied:'/usr/lib/python2.7/urllib.pyc'
4、又stack了一番,发现可能是没有权限,又不想chmod 777,所以我把urllib拷贝出来,重新执行
5、重新执行py_compile编译动作
6、把生成的urllib.pyc 拷贝回源路径,注意要用sudo权限
7、测试是否新生成的pyc文件有效
测试结果OK(Ps:Really 折腾)
from urllib import urlopen
webpage = urlopen('http://www.python.org')
AttributeError: 'module' object has no attribute'urlopen'
我是ubuntu 12.04 + 自带Python 2,7.3
一开始以为是什么Python和Python3不兼容导致,然后在urllib2、urllib还有什么urllib2.request一直反复折腾。。。。
后来stackoverflow一下,发现时urllib.pyc文件不对导致,需要重新编译生成一个该文件。
具体pyc文件是啥就不说了,自行百度。
下面说下我的解决过程:
1、找到urllib.pyc文件路径,并进入该路径
2、用sudo删除该文件
3、但是compile编译重新生成.pyc文件,报错:IOError: [Errno 13] Permission denied:'/usr/lib/python2.7/urllib.pyc'
4、又stack了一番,发现可能是没有权限,又不想chmod 777,所以我把urllib拷贝出来,重新执行
5、重新执行py_compile编译动作
6、把生成的urllib.pyc 拷贝回源路径,注意要用sudo权限
7、测试是否新生成的pyc文件有效
测试结果OK(Ps:Really 折腾)
相关文章推荐
- python AttributeError: 'module' object has no attribute 'dumps'解决办法
- Python基础学习-'module' object has no attribute 'urlopen'解决方法
- AttributeError: 'module' object has no attribute 'urlopen'
- python3 报错: AttributeError: 'module' object has no attribute 'urlopen'
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- python3.6 出现AttributeError: module 'urllib' has no attribute 'urlopen'
- Python 3.x中导入urllib出现AttributeError: module 'urllib' has no attribute 'urlopen'
- python AttributeError: 'module' object has no attribute 'setdefaultencoding'
- Python3.X识别混合编码,顺便解决“AttributeError: 'module' object has no attribute 'urlopen'”
- Python3.X出现AttributeError: module 'urllib' has no attribute 'urlopen'错误
- AttributeError: 'module' object has no attribute 'text_format'
- python “AttributeError: '_csv.reader' object has no attribute'next'” 报错的解决办法
- AttributeError: 'module' object has no attribute 'text_format'
- AttributeError: 'module' object has no attribute 'LabelMap'
- python 中出现的AttributeError: 'module' object has no attribute '_handlerList'
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- AttributeError: 'module' object has no attribute 'Spider' 解决了
- AttributeError: 'module' object has no attribute 'AF_INET'
- AttributeError: 'module' object has no attribute 'Serial'
- [数字图像处理实验][python+opencv]'module' object has no attribute 'cv'