栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

IronPython:使用pyc.py编译的EXE无法导入模块“ OS”

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IronPython:使用pyc.py编译的EXE无法导入模块“ OS”

构建一个可以分发的Ironpython EXE有点棘手-尤其是在使用标准库的元素时。我的典型解决方案如下:

我将我需要的所有stdlib模块复制到一个文件夹中(通常是出于完整性的考虑),并使用此脚本来构建我的exe。在此示例中,我有两个文件
FredMain.pyFredSOAP.py ,它们被编译成一个名为 Fred_Download_Tool 的EXE。


import syssys.path.append(r'C:Program FilesIronPython 2.7Lib')sys.path.append(r'C:Program FilesIronPython 2.7')import clrclr.AddReference('IronPython')clr.AddReference('IronPython.Modules')clr.AddReference('Microsoft.scripting.metadata')clr.AddReference('Microsoft.scripting')clr.AddReference('Microsoft.Dynamic')clr.AddReference('mscorlib')clr.AddReference('System')clr.AddReference('System.Data')## adapted from os-path-walk-example-3.pyimport os, globimport fnmatchimport pycdef doscopy(filename1):    print filename1    os.system ("copy %s .\binDebug%s" % (filename1, filename1))class GlobDirectoryWalker:    # a forward iterator that traverses a directory tree    def __init__(self, directory, pattern="*"):        self.stack = [directory]        self.pattern = pattern        self.files = []        self.index = 0    def __getitem__(self, index):        while 1: try:     file = self.files[self.index]     self.index = self.index + 1 except IndexError:     # pop next directory from stack     self.directory = self.stack.pop()     self.files = os.listdir(self.directory)     self.index = 0 else:     # got a filename     fullname = os.path.join(self.directory, file)     if os.path.isdir(fullname) and not os.path.islink(fullname) and fullname[-4:]<>'.svn':         self.stack.append(fullname)     if fnmatch.fnmatch(file, self.pattern):         return fullname#Build StdLib.DLLgb = glob.glob(r".Lib*.py")gb.append("/out:StdLib")#print ["/target:dll",]+gbpyc.Main(["/target:dll"]+gb)#Build EXEgb=["/main:FredMain.py","FredSOAP.py","/target:exe","/out:Fred_Download_Tool"]pyc.Main(gb)#CopyFiles to Release Directorydoscopy("StdLib.dll")doscopy("Fred_Download_Tool.exe")doscopy("Fred_Download_.dll")#Copy DLLs to Release Directoryfl = ["IronPython.dll","IronPython.Modules.dll","Microsoft.Dynamic.dll","Microsoft.scripting.Debugging.dll","Microsoft.scripting.dll","Microsoft.scripting.ExtensionAttribute.dll","Microsoft.scripting.Core.dll"]for f in fl:doscopy(f)

准备编译时,在脚本中添加以下内容。这允许程序使用我DLL中的标准模块,而不是Python
Install。如果要分发给未安装Python的人,这是必需的。只需确保在创建安装程序时包括必要的DLL。

#References to created DLL of python modulesclr.AddReference('StdLib')


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624621.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号