py2exe ImportError: No module named iterators,ImportError: MemoryLoadLibrary failed loading win32ap

本文介绍了解决使用py2exe编译Python程序时遇到的两个常见问题:ImportError: No module named iterators 和 ImportError: MemoryLoadLibrary failed loading win32api。提供了两种解决方案,并详细解释了如何修改setup.py文件。

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

1、ImportError: No module named iterators,ImportError

把使用email库缺失的模块都加进去:

方法一:

在setup.py添加如下代码,

from distutils.core import setup

import py2exe, sys, os

#sys.argv.append('py2exe')

includes = ['email.charset', 'email.encoders', 'email.generator', 'email.header', 'email.iterators', 'email.mime.audio', 'email.mime.base', 'email.mime.image','email.mime.multipart','email.mime.text','email.message', 'email.utils', 'email.base64mime']

setup(

    options = {'py2exe':

                {'bundle_files': 1,

                 'includes':includes

                  }},

    console = [test.py'],

    zipfile = None,

)

方法二:

只需要在你要编译的相应的程序文件中我的文件test.py加放如下import
要注意大小写哈___


import smtplib,email,sys
from email.mime.text import MIMEText
from email.Message import Message
import email.Utils
import email.generator
import email.base64MIME
import email.iterators
import email.message

相应用到py2exe setup.py文件中,相关代码如下:


from distutils.core import setup
import py2exe


setup(
        console=[server.py'],
        options={
                "py2exe":{

                       'bundle_files': 1,
                        "unbuffered": True,
                        "optimize": 2,
                        "includes": ["email"]
                }
        }
)


2、ImportError: MemoryLoadLibrary failed loading win32ap

setup.py中添加如下代码: setup的 option 选项中加入 "dll_excludes": [ "mswsock.dll","powrprof.dll" ]即可,

原因:py2exe mistakenly added powrprof.dlland mswsock.dll to the package. Windows XP contains its own copiesof these files though

setup(

    options = {'py2exe':

                {'bundle_files': 1,

                 "dll_excludes": [ "mswsock.dll","powrprof.dll" ]

                 }},

    console = [test.py'],

    zipfile = None,

)

参考文献:

http://www.alarmchang.com/wiki/index.php?title=Python&diff=prev&oldid=618

http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed

http://hi.baidu.com/jetqu2003/blog/item/39770003abb766713812bb4e.html



内存加载动态库 MemoryLoadLibrary 有例子。 /* * Memory DLL loading code * Version 0.0.3 * * Copyright (c) 2004-2013 by Joachim Bauch / mail@joachim-bauch.de * http://www.joachim-bauch.de * * The contents of this file are subject to the Mozilla Public License Version * 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is MemoryModule.h * * The Initial Developer of the Original Code is Joachim Bauch. * * Portions created by Joachim Bauch are Copyright (C) 2004-2013 * Joachim Bauch. All Rights Reserved. * */ #ifndef __MEMORY_MODULE_HEADER #define __MEMORY_MODULE_HEADER #include typedef void *HMEMORYMODULE; typedef void *HMEMORYRSRC; typedef void *HCUSTOMMODULE; #ifdef __cplusplus extern "C" { #endif typedef HCUSTOMMODULE (*CustomLoadLibraryFunc)(LPCSTR, void *); typedef FARPROC (*CustomGetProcAddressFunc)(HCUSTOMMODULE, LPCSTR, void *); typedef void (*CustomFreeLibraryFunc)(HCUSTOMMODULE, void *); /** * Load DLL from memory location. * * All dependencies are resolved using default LoadLibrary/GetProcAddress * calls through the Windows API. */ HMEMORYMODULE MemoryLoadLibrary(const void *); /** * Load DLL from memory location using custom dependency resolvers. * * Dependencies will be resolved using passed callback methods. */ HMEMORYMODULE MemoryLoadLibraryEx(const void *, CustomLoadLibraryFunc, CustomGetProcAddressFunc, CustomFreeLibraryFunc, void *); /** * Get address of exported method. */ FARPROC MemoryGetProcAddress(HMEMORYMODULE, LPCSTR); /** * Free previously loaded DLL. */ void MemoryFreeLibrary(HMEMORYMODULE); /** * Find the location of
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值