【问题标题】:Python executable file closes without showing outputsPython 可执行文件关闭而不显示输出
【发布时间】:2019-10-13 14:34:13
【问题描述】:

我在 Python 语言中创建了一个在 Jupiter 上使用 Google Books API 的代码。我想创建一个 .exe 文件以便在其他 PC 上使用它。我用pyinstaller name_of_the_script.py 完成了它,但是当我在输入第二个输入后执行它时,命令窗口会消失而不显示输出,如果我在最后放置一个输入行以使脚本保持活动状态直到我按下一个键.

代码如下:

import requests

quote = input('Inserisci la citazione: ')
lingua = input('\nInserisci lingua (sigla, ad esempio ''it'' per ''Italiano''): ')


key = 'xxxxxxxxx'
parms = {'q':quote, 'key':key, 'maxResults':5,'langRestrict':lingua}

r = requests.get(url='https://www.googleapis.com/books/v1/volumes', params = parms)
rj = r.json()

for i in range(0,3):
    print('\n' + rj['items'][i]['volumeInfo']['title'] + '\n')
    for authors in rj['items'][i]['volumeInfo']['authors']:
        print(authors)
    print('\n' + '\n')

input('press enter to quit')

怎么了?

【问题讨论】:

  • 它可能在执行过程中崩溃了。您可以在代码周围添加try catch 语句并重试吗?这是使用pyinstaller...的问题之一...
  • 我会试试的。如果我什么都不考虑怎么办?例如,我应该将我使用的库放在 .exe 的同一文件夹中吗?对不起,我不是程序员。
  • 我忘了问:在Python中运行它时它运行良好,而不运行.exe?

标签: python python-3.x google-api exe google-books


【解决方案1】:

我解决了!

.ipynb 文件转换为 .py 文件时出错。 为了转换它,我使用了在 SO 中找到的代码,现在它可以工作了。

帮助我的帖子在这里:

Is it possible to generate an executable (.exe) in a jupyter-notebook?

【讨论】:

    猜你喜欢
    • 2012-01-25
    • 2021-05-19
    • 2022-12-10
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多