import_pywin32_system_module

修复方法:

编辑 X:/Python27/Lib/site-packages/win32/lib/pywintypes.py 第114行

    if sys.version_info < (3,0):
pass
# This is for AssertionError when running BanBanTong project
# 2015-02-10 MH 将下面两行注释掉
## assert sys.modules[modname] is old_mod
## assert mod is old_mod

编辑好了的整个文件如下

# Magic utility that "redirects" to pywintypesxx.dll
import imp, sys, os
def __import_pywin32_system_module__(modname, globs):
# This has been through a number of iterations. The problem: how to
# locate pywintypesXX.dll when it may be in a number of places, and how
# to avoid ever loading it twice. This problem is compounded by the
# fact that the "right" way to do this requires win32api, but this
# itself requires pywintypesXX.
# And the killer problem is that someone may have done 'import win32api'
# before this code is called. In that case Windows will have already
# loaded pywintypesXX as part of loading win32api - but by the time
# we get here, we may locate a different one. This appears to work, but
# then starts raising bizarre TypeErrors complaining that something
# is not a pywintypes type when it clearly is! # So in what we hope is the last major iteration of this, we now
# rely on a _win32sysloader module, implemented in C but not relying
# on pywintypesXX.dll. It then can check if the DLL we are looking for
# lib is already loaded.
if not sys.platform.startswith("win32"):
# These extensions can be built on Linux via the 'mainwin' toolkit.
# Look for a native 'lib{modname}.so'
# NOTE: The _win32sysloader module will probably build in this
# environment, so it may be better to use that here too.
for ext, mode, ext_type in imp.get_suffixes():
if ext_type==imp.C_EXTENSION:
for path in sys.path:
look = os.path.join(path, "lib" + modname + ext)
if os.path.isfile(look):
mod = imp.load_module(modname, None, look,
(ext, mode, ext_type))
# and fill our namespace with it.
# XXX - if this ever moves to py3k, this will probably
# need similar adjustments as below...
globs.update(mod.__dict__)
return
raise ImportError("No dynamic module " + modname)
# See if this is a debug build.
for suffix_item in imp.get_suffixes():
if suffix_item[0]=='_d.pyd':
suffix = '_d'
break
else:
suffix = ""
filename = "%s%d%d%s.dll" % \
(modname, sys.version_info[0], sys.version_info[1], suffix)
if hasattr(sys, "frozen"):
# If we are running from a frozen program (py2exe, McMillan, freeze)
# then we try and load the DLL from our sys.path
# XXX - This path may also benefit from _win32sysloader? However,
# MarkH has never seen the DLL load problem with py2exe programs...
for look in sys.path:
# If the sys.path entry is a (presumably) .zip file, use the
# directory
if os.path.isfile(look):
look = os.path.dirname(look)
found = os.path.join(look, filename)
if os.path.isfile(found):
break
else:
raise ImportError("Module '%s' isn't in frozen sys.path %s" % (modname, sys.path))
else:
# First see if it already in our process - if so, we must use that.
import _win32sysloader
found = _win32sysloader.GetModuleFilename(filename)
if found is None:
# We ask Windows to load it next. This is in an attempt to
# get the exact same module loaded should pywintypes be imported
# first (which is how we are here) or if, eg, win32api was imported
# first thereby implicitly loading the DLL. # Sadly though, it doesn't quite work - if pywintypesxx.dll
# is in system32 *and* the executable's directory, on XP SP2, an
# import of win32api will cause Windows to load pywintypes
# from system32, where LoadLibrary for that name will
# load the one in the exe's dir.
# That shouldn't really matter though, so long as we only ever
# get one loaded.
found = _win32sysloader.LoadModule(filename)
if found is None:
# Windows can't find it - which although isn't relevent here,
# means that we *must* be the first win32 import, as an attempt
# to import win32api etc would fail when Windows attempts to
# locate the DLL.
# This is most likely to happen for "non-admin" installs, where
# we can't put the files anywhere else on the global path. # If there is a version in our Python directory, use that
if os.path.isfile(os.path.join(sys.prefix, filename)):
found = os.path.join(sys.prefix, filename)
if found is None:
# Not in the Python directory? Maybe we were installed via
# easy_install...
if os.path.isfile(os.path.join(os.path.dirname(__file__), filename)):
found = os.path.join(os.path.dirname(__file__), filename)
if found is None:
# give up in disgust.
raise ImportError("No system module '%s' (%s)" % (modname, filename))
# py2k and py3k differences:
# On py2k, after doing "imp.load_module('pywintypes')", sys.modules
# is unchanged - ie, sys.modules['pywintypes'] still refers to *this*
# .py module - but the module's __dict__ has *already* need updated
# with the new module's contents.
# However, on py3k, sys.modules *is* changed - sys.modules['pywintypes']
# will be changed to the new module object.
# SO: * on py2k don't need to update any globals.
# * on py3k we update our module dict with the new module's dict and
# copy its globals to ours.
old_mod = sys.modules[modname]
# Python can load the module
mod = imp.load_dynamic(modname, found)
# Check the sys.modules[] behaviour we describe above is true...
if sys.version_info < (3,0):
pass
# This is for AssertionError when running BanBanTong project
# 2015-02-10 MH
## assert sys.modules[modname] is old_mod
## assert mod is old_mod
else:
assert sys.modules[modname] is not old_mod
assert sys.modules[modname] is mod
# as above - re-reset to the *old* module object then update globs.
sys.modules[modname] = old_mod
globs.update(mod.__dict__) __import_pywin32_system_module__("pywintypes", globals())

[BUGFIX]__import_pywin32_system_module__的更多相关文章

  1. 在Activiti官方源码上提交的两个bugfix

    前段时间在Activiti官方源码上提交了两个bugfix,截图为证. 第1个是BPMN model输出的bug:

  2. pymongo bugfix后记

    有网友反馈py-mongo-sync同步异常,检查发现curosr[0]取查询结果第一个文档时报错"no such item for Cursor instance". 这里的逻辑 ...

  3. BugFix:URL or HTTP headers are too long (IP=127.0.0.1)

    错误提示: URL or HTTP headers are too long (IP=127.0.0.1) com.caucho.server.dispatch.BadRequestException ...

  4. TypeError: can't compare offset-naive and offset-aware datetimes bugfix

    参考:https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/#naive-and-aware-datetime-objects 起因: ...

  5. css3 animation 在某些浏览器中特别快 bugfix

    今天在一款三星 4.2.2 的 webview 里,出现 animation 特别快的问题,把: .xxx{ -webkit-animation: xxx 24s linear infinite; } ...

  6. IDE Fix Pack 6.4.2 released (bugfix release)

    IDE Fix Pack 6.4.2 addresses two bugs. It fixes an issue with the TCustomListBox.ResetContent patch ...

  7. 第二十六课 典型问题分析(Bugfix)

    问题1: glibc中的strdup实现如下: 没有对参数s进行空指针判断. 我们的Exception.cpp中应做改进: 在第12行进行判断空指针操作. 问题2: t1在析构时会抛出异常,我们在re ...

  8. 数据结构开发(7):典型问题分析(Bugfix)

    0.目录 1.创建异常对象时的空指针问题 2.LinkList 中的数据元素删除 3.LinkList 中遍历操作与删除操作的混合使用 4.StaticLinkList 中数据元素删除时的效率问题 5 ...

  9. [bugfix]copy属性参数将NSMutableArray变为NSArray类型

    问题:NSMutableArray 声明为 copy 属性参数后即使接受NSMutableArray变量依然为NSArray变量 测试: 属性申明为: 1 @property (nonatomic, ...

随机推荐

  1. linux+nginx+tomcat负载均衡,实现session同步

    linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...

  2. tcp_tw_reuse 与 net.ipv4.tcp_tw_recycle

    最近发现几个监控用的脚本在连接监控数据库的时候偶尔会连不上,报错: Couldn't connect to host:3306/tcp: IO::Socket::INET: connect: Cann ...

  3. Using Sessions and Session Persistence---reference

    Using Sessions and Session Persistence The following sections describe how to set up and use session ...

  4. linux服务器上

    命令行>mysql -uwin -pwin2009进入mysql command状态>use mindo时入mindo数据库>source 500sql.txt执行sql

  5. java注解研究

    注解作用 常见的作用有以下几种: 生成文档.这是最常见的,也是java 最早提供的注解.常用的有@see @param @return @author等. 跟踪代码依赖性,实现替代配置文件功能.比较常 ...

  6. 3.linux安装vsftpd服务

    1.首先查看本地是否安装了vsftpd rpm -qa |grep vsftpd 2.安装vsftpd: yum install vsftpd 3.查询当前ftp状态 chkconfig --list ...

  7. hdu 1563 Find your present!

    Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. 常见的IE6兼容以及css兼容

    IE6虽然随着XP系统退出市场在国外基本基本消失,但是在国内依然占据很大的市场份额.政务网站.页游官网等依然要考虑到IE6用户的体验.如果你的网站使用CSS3等“新技术”时,就必须果断放弃IE6的兼容 ...

  9. jQuery Validate验证框架使用

    jQuery Validate使用前的准备,需要下载相应js包括:1.jquery.validate.min.js.2.additional-methods.min.js. 当然必不可少的js jQu ...

  10. Java——有关日期的方法

    1.日期转换成String格式化输出: public String getDate() { SimpleDateFormat format = new SimpleDateFormat("y ...