微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于python脚本的EXE文件

我正在使用python 2.7和py2exe来尝试为我的脚本制作一个exe文件。 但它不是很好..我的文件工作完美,直到我添加py2exe命令我在这里做错了什么? 我需要知道如何编写设置函数调用它,以便python知道创build和EXE文件不只是一个编译.py。 这也是尝试使用Windows操作系统。

from time import strftime import os.path # setup.py import py2exe setup(console=["LogFile.py"]) def main(): getTime() def getTime(): time = strftime("%Y-%m-%d %I:%M:%s") printTime(time) def printTime(time): savePath = "C:UsersNicholasDocuments" logFile = "LogInLog.txt" files = open(os.path.join(savePath,logFile),"a+") openPosition = files.tell() files.write("A LogIn occured.") files.write(time) files.seek(openPosition) print(files.read()) files.close() main()

将Python 2.7.6添加到Windowsregistry中

Python py2exe ImportError:MemoryLoadLibrary无法加载glib _glib.pyd

使用opencv为应用程序创build可执行文件

创build一个独立的Windows EXE,不需要pythonXX.dll

用py2exe编译exe文件包括cefpython

这种方式不行

首先,从脚本中删除setup行。 安装脚本是一个不同的脚本。 你的脚本已修复:

from time import strftime import os.path def main(): getTime() def getTime(): time = strftime("%Y-%m-%d %I:%M:%s") printTime(time) def printTime(time): savePath = r"C:UsersNicholasDocuments" logFile = "LogInLog.txt" files = open(os.path.join(savePath,"a+") openPosition = files.tell() files.write("A LogIn occured.") files.write(time) files.seek(openPosition) print(files.read()) files.close()

然后创建一个名为setup.py的文件

import py2exe from distutils.core import setup setup(console=["LogFile.py"])

然后键入(在命令提示符中, 而不是从python解释器中 ):

python setup.py py2exe

它会在dist subdir中创建可执行文件和辅助文件

之后,去dist

C:DATAjffdatapythonstackoverflowdist>LogFile.exe Traceback (most recent call last): File "LogFile.py",line 25,in <module> File "LogFile.py",line 6,in main File "LogFile.py",line 10,in getTime File "LogFile.py",line 15,in printTime FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Nicholas\Documents\LogInLog.txt'

崩溃,正常我没有你的目录:它的作品!

看看这个py2exe教程 。

你的错误是:1. from distutils.core import setup错过2.没有创建一个新的文件来使用py2exe。

您需要:1.删除import py2exe并setup(console=["LogFile.py"]) 2.创建新文件“psetup.py”,代码如下:

from distutils.core import setup import py2exe setup(console=["your_code_name.py"])

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐