[英]TKinter application runs perfectly fine in Visual Studio Code but crashes as an .exe
[英]file in .exe not running properly but in visual studio code is working fine
我正在寻找有关如何使 my.exe python 文件运行良好的解决方案,就像在 Visual Studio 代码中一样。 将 python 文件转换为 .exe 后,它无法正常运行,因为它显示回溯错误。 Traceback Error ..使用 cmd 中的 --onefile -w 再次重新转换
代码:
from time import sleep
from newspaper import Article, Config
import nltk
from newspaper.article import ArticleException, ArticleDownloadState
def get_News():
while True:
print ("Enter URL: ")
url = input('')
print("\n")
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
config = Config()
config.browser_user_agent = user_agent
config.request_timeout = 10
article = Article(url, config=config, lang='en')
slept = 0
article.download()
article.parse()
title = article.title
author = article.authors
pub_date = article.publish_date
text = article.text
article.nlp()
print('Display Title, Author and Publish Date:')
print(title ,author, pub_date)
print ('\n' +'Display Text from Article: ' + '\n' + text)
print ('\n' + 'Display Article Summary: ')
print(article.summary)
print('\n')
print('Display Keywords: ')
print(article.keywords)
if url == '':
print('No URL Found. Exiting the Program...')
break
if __name__ == '__main__':
get_News()
我正在使用 Visual Studio Code 并转换为.exe,我使用 py -m PyInstaller --onefile -.py
感谢您的帮助和解决方案!
请使用命令PyInstaller --onefile <filename>
而不是你的。 您不是在编写只有 UI 的程序, -w
表示不使用命令 window,指的是stdin
、 stdout
、 stderr
无效。 这意味着input()
、 print()
等不可用。
不知何故,我设法解决了它,好像报纸 \article.py 不在我的 exe 程序的文件目录中。 所以我从 Python 复制粘贴报纸文件夹并将其粘贴到我的 exe 程序的文件中,它终于工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.