首先,我是编程,python和这个论坛的新手,对于任何错误都很抱歉。
我写了一个python脚本,但希望能够在没有安装python的计算机上运行它,所以我做了一些研究,发现我需要下载一个程序才能将py转换为exe。 cx_freeze是唯一支持python 3.4的人。
我按照热门YouTube视频(https://www.youtube.com/watch?v=XHcDHSWRCRQ)中的说明操作,但是当我双击exe时,命令框会弹出一瞬间然后关闭。有一些文字,但我读得太快了。
看起来这些线程存在同样的问题,但是没有得到答复。有什么想法吗?
Command prompt disappears with cx_freeze
cx_Freeze exe file opens for a second then closes
谢谢!
编辑:如果有帮助,这是我的setup.py
from cx_Freeze import setup, Executable
setup(
name = "Teacher Pages Search" ,
version = "1" ,
description = "By Gambiteer" , executables = [Executable("Teacher Pages Search.py")] ,
)
这是教师页面Search.py
import urllib.request
import html.parser
import webbrowser
class MyHTMLParser(html.parser.HTMLParser):
def __init__(self):
super().__init__(False)
self.teacherLink = False
self.url = ""
def handle_starttag(self, tag, attrs):
if tag == 'a':
for combo in attrs:
if "sw-directory-item" in combo[1]:
self.teacherLink = True
if self.teacherLink is True:
if "http:" in combo[1]:
self.url = combo[1]
def handle_data(self, data):
data = data.lower()
data = data.replace("'","")
data = data.replace("\\","")
data = data.replace(" ","")
if self.teacherLink is True:
for teacher in teacherList:
if teacher in data:
webbrowser.open(self.url)
self.teacherLink = False
teacherListInput = input("Enter the last name of your teachers, without punctuation, separated by commas:\n")
teacherListInput = teacherListInput.replace(" ","")
teacherList = list()
while teacherListInput.find(',') != -1:
commaLoc = teacherListInput.find(',')
teacherName = teacherListInput[0:commaLoc]
teacherList.append(teacherName)
teacherListInput = teacherListInput[commaLoc+1:]
teacherList.append(teacherListInput)
f = urllib.request.urlopen("http://www.scarsdaleschools.k12.ny.us/site/Default.aspx?PageType=1&SiteID=65&ChannelID=94&DirectoryType=6")
webpage = f.read()
parser = MyHTMLParser()
html_parser = html.parser.HTMLParser()
unescaped = html_parser.unescape(str(webpage))
parser.feed(unescaped)
input("Press enter to exit")