大白摸索记:python中出现No module named 'urllib2'的解决办法(五)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/hhdhz/article/details/96511029

问题所在:因为在py3中,

urllib2模块已分为Python 3中的几个模块命名
urllib.request

urllib.error

1

解决方案:在python3.3里面,用urllib.request代替urllib2

2
然后就阔以啦!!!

展开阅读全文

python:no module named MySQLdb

03-05

想用django开发网站。使用的是python2.7,操作系统win10.已经安装好了Anaconda和mysql。现在想进行连接数据库,已经在网站下载并安装了多个版本的python-mysql驱动(1.2.3版本等),然后再import MySQLdb,还是提示no module named MySQLdbrnrnrn在C:\Anaconda2\Lib\site-packages也已经有了C:\Anaconda2\Lib\site-packages\MySQL_python-1.2.3-py2.7.egg-info和C:\Anaconda2\Lib\site-packages\MySQLdb。rnrn为什么就是不能成功呢?rnrndjango在启动服务的时候,错误为:rnC:\Anaconda2\Django-1.9.4\django\bin\hello>python manage.py runsever 0.0.0.0:8080rnTraceback (most recent call last):rn File "manage.py", line 10, in rn execute_from_command_line(sys.argv)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\core\management\__init__.py", line 353, in execute_from_command_linern utility.execute()rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\core\management\__init__.py", line 327, in executern django.setup()rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\__init__.py", line 18, in setuprn apps.populate(settings.INSTALLED_APPS)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\apps\registry.py", line 108, in populatern app_config.import_models(all_models)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\apps\config.py", line 202, in import_modelsrn self.models_module = import_module(models_module_name)rn File "F:\Anaconda\lib\importlib\__init__.py", line 37, in import_modulern __import__(name)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\contrib\auth\models.py", line 4, in rn from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManagerrn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\contrib\auth\base_user.py", line 49, in rn class AbstractBaseUser(models.Model):rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\models\base.py", line 108, in __new__rn new_class.add_to_class('_meta', Options(meta, app_label))rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\models\base.py", line 299, in add_to_classrn value.contribute_to_class(cls, name)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\models\options.py", line 263, in contribute_to_classrn self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\__init__.py", line 36, in __getattr__rn return getattr(connections[DEFAULT_DB_ALIAS], item)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\utils.py", line 212, in __getitem__rn backend = load_backend(db['ENGINE'])rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\utils.py", line 116, in load_backendrn return import_module('%s.base' % backend_name)rn File "F:\Anaconda\lib\importlib\__init__.py", line 37, in import_modulern __import__(name)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\backends\mysql\base.py", line 28, in rn raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)rndjango.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb 论坛

关于python本地调试出现No module named google.appengine.ext 的问题

08-25

不知道什么原因。rn我有一个项目虽然本地调试出现这个问题,但是可以上传GAE成功的。rn但是另外一个项目也出现这个错误,但是不能上传成功。rn因为python调试器只能显示一个错误同一时间,我怀疑还有其他语法错误,但是这个错误过不去,其他错误也不能调试出来。rn急,有高手知吗?rnrn可以加我QQ 414522115rnrn[code=Python]rn#main.pyrn################## 主模块 #####################rnrnfrom google.appengine.ext import webapprnfrom google.appengine.ext.webapp.util import run_wsgi_apprndef main():rn application = webapp.WSGIApplication(rn [('/.*', DefaultModule),rn ('/bbs', BbsModule),rn ('/joke', JokeModule),rn ('/music', MusicModule),rn ('/tv', TvModule),rn ('/film', FilmModule),rn ('/video', VideoModule),rn ('/game', GameModule)rn ],debug=False) rn rn run_wsgi_app(application) rn rnif __name__ == "__main__": rn main()rnrn#index.pyrnrn# -*- coding: UTF-8 -*-rnimport masterrnimport wsgiref.handlersrnimport re,os,cgi,time,mimetypes,md5,urllibrnfrom google.appengine.ext import dbrnfrom google.appengine.api import usersrnfrom google.appengine.ext import searchrnfrom google.appengine.ext import webapprnfrom google.appengine.ext.webapp import templaternfrom google.appengine.ext.webapp.util import run_wsgi_apprnfrom datetime import datetime, timedeltarnfrom data import *rnrnclass DefaultModule(webapp.RequestHandler):rn def get(self):rn s = render(self, 'index.html')rn self.response.out.write(s)rnrn def render(self, file, vars = ):rn vars['master'] = masterrn return template.render(os.path.join(os.path.dirname(__file__), "../render/" + file), vars)rnrn[/code] 论坛

使用python编写发邮件,出现错误No module named 'email'

02-23

报错信息为:rnTraceback (most recent call last):rnFile "sendyoujian_20170222.py", line 7, in rnimport email.utilsrnImportError: No module named 'email'rn已把本地含有email.py的所有文件都删除掉,仍然报错,查了很多资料不知道原因出在哪了,所以向各位大神们求教,谢谢!rnrn正文为:rnimport email.utilsrnfrom email import encodersrnfrom email.header import Headerrnfrom email.mime.base import MIMEBasernfrom email.mime.text import MIMETextrnfrom email.mime.multipart import MIMEMultipartrnfrom email.mime.image import MIMEImagernfrom email.utils import parseaddr, formataddr, formatdaternrnimport smtplib rnrndef _format_addr(s): rn name, addr = parseaddr(s)rn return formataddr(Header(name, 'utf-8').encode(), addr)rnfrom_addr = input('From: ')rnpassword = input('Password: ')rnto_addr = input('To: ')rnsmtp_server = input('SMTP server:')rnrn#邮件对象rnmsg = MIMEMultipart() rnmsg['From'] = _format_addr('Python爱好者<%s>'% from_addr)rn#msg['To']接收的是字符串而不是list,如果有多个邮件地址,用逗号(,)分隔rnmsg['To'] = _format_addr('管理员<%s>'% to_addr)rnmsg['Subject'] = Header('来自SMTP的问候……', 'utf-8').encode()rnmsg.attach(MIMEText('send with file...', 'plain', 'utf-8'))rnrnwith open('/User/michael/Downloads/test.png', 'rb') as f:rn mime = MIMEBase('image','png', filename = 'test.png')rn mime.add_header('Content-Disposition','attachment', filename='test.png')rn mime.add_header('Content-ID','<0>')rn mime.add_header('X-Attachment-Id','0')rn mime.set_payload(f.read())rn encoders.encode_base64(mine)rn msg.attach(mine)rnserver = smtplib.SMTP(smtp_server, 25) rnrn#set_debuglevel(1)rnrnserver.set_debuglevel(1)rnrn#login方法用来登录SMTP服务器rnserver.login(from_addr, password)rnrnserver.sendmail(from_addr,[to_addr], msg.as_string())rnserver.quit() 论坛

ImportError: No module named '_pywrap_tensorflow_internal'

11-05

tensorflow==1.5.0 安装成功;继续安装gpu版本,按系统提示再安装 CUDA-9.0, cuDNN-7.0: cuda_9.0.176_win10_network以及patch1-4 / cudnn-9.0-windows10-x64-v7.3.1.20. 运行‘import tensorflow as tf’后报错: ImportError: No module named '_pywrap_tensorflow_internal'rnrn谢谢帮助rnrn ---------------------------------------------------------------------------rnImportError Traceback (most recent call last)rnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()rn 17 try:rn---> 18 return importlib.import_module(mname)rn 19 except ImportError:rnrnC:\Program Files\Anaconda3\lib\importlib\__init__.py in import_module(name, package)rn 125 level += 1rn--> 126 return _bootstrap._gcd_import(name[level:], package, level)rn 127 rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap.py in _load_unlocked(spec)rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap.py in module_from_spec(spec)rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap_external.py in create_module(self, spec)rnrnC:\Program Files\Anaconda3\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)rnrnImportError: DLL load failed: 找不到指定的程序。rnrnDuring handling of the above exception, another exception occurred:rnrnImportError Traceback (most recent call last)rnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in ()rn 57 rn---> 58 from tensorflow.python.pywrap_tensorflow_internal import *rn 59 from tensorflow.python.pywrap_tensorflow_internal import __version__rnrnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in ()rn 20 return importlib.import_module('_pywrap_tensorflow_internal')rn---> 21 _pywrap_tensorflow_internal = swig_import_helper()rn 22 del swig_import_helperrnrnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()rn 19 except ImportError:rn---> 20 return importlib.import_module('_pywrap_tensorflow_internal')rn 21 _pywrap_tensorflow_internal = swig_import_helper()rnrnC:\Program Files\Anaconda3\lib\importlib\__init__.py in import_module(name, package)rn 125 level += 1rn--> 126 return _bootstrap._gcd_import(name[level:], package, level)rn 127 rnrnImportError: No module named '_pywrap_tensorflow_internal'rnrnDuring handling of the above exception, another exception occurred:rnrnImportError Traceback (most recent call last)rn in ()rn----> 1 import tensorflow as tfrnrnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\__init__.py in ()rn 22 rn 23 # pylint: disable=wildcard-importrn---> 24 from tensorflow.python import *rn 25 # pylint: enable=wildcard-importrn 26 rnrnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in ()rn 47 import numpy as nprn 48 rn---> 49 from tensorflow.python import pywrap_tensorflowrn 50 rn 51 # Protocol buffersrnrnC:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in ()rn 72 for some common reasons and solutions. Include the entire stack tracern 73 above this error message when asking for help.""" % traceback.format_exc()rn---> 74 raise ImportError(msg)rn 75 rn 76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-longrnrnImportError: Traceback (most recent call last):rn File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helperrn return importlib.import_module(mname)rn File "C:\Program Files\Anaconda3\lib\importlib\__init__.py", line 126, in import_modulern return _bootstrap._gcd_import(name[level:], package, level)rn File "", line 986, in _gcd_importrn File "", line 969, in _find_and_loadrn File "", line 958, in _find_and_load_unlockedrn File "", line 666, in _load_unlockedrn File "", line 577, in module_from_specrn File "", line 906, in create_modulern File "", line 222, in _call_with_frames_removedrnImportError: DLL load failed: 找不到指定的程序。rnrnDuring handling of the above exception, another exception occurred:rnrnTraceback (most recent call last):rn File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in rn from tensorflow.python.pywrap_tensorflow_internal import *rn File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in rn _pywrap_tensorflow_internal = swig_import_helper()rn File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helperrn return importlib.import_module('_pywrap_tensorflow_internal')rn File "C:\Program Files\Anaconda3\lib\importlib\__init__.py", line 126, in import_modulern return _bootstrap._gcd_import(name[level:], package, level)rnImportError: No module named '_pywrap_tensorflow_internal'rnrnrnFailed to load the native TensorFlow runtime.rnrnSee https://www.tensorflow.org/install/install_sources#common_installation_problemsrnrnfor some common reasons and solutions. Include the entire stack tracernabove this error message when asking for help. 问答

没有更多推荐了,返回首页