【问题标题】:Difficulty opening an exeexe打开困难
【发布时间】:2020-10-02 18:30:40
【问题描述】:

我编写了一个 youtube 转换器,当我从 pycharm 运行它时它工作正常。我尝试了几种方法来使用 pyinstaller 从下面的 .py 文件中创建一个 exe 文件。

从 cd 中,在正确的目录中,

当我尝试pyinstaller --onefile -w filename.pypyinstaller --onefile filename.py 时,当我尝试打开可执行文件时,出现致命错误无法运行脚本。

当我尝试pyinstaller filename.pypython -m PyInstaller filename.py,然后尝试打开可执行文件时,cmd 闪烁,然后什么也没有。

从pycharm,当我运行程序时,tkinter打开并且所有功能都很好。

这是我的代码

from tkinter import *
from pytube import YouTube
import youtube_dl

window = Tk()
window.title("Convertiseur Youtube 1.0")
window.configure(background="silver")
window.geometry("600x250")

def clickvideo():
   url = textentry.get()
   YouTube(url).streams.filter(file_extension='mp4').first().download()
   textentry.delete(0, END)
   status.set("Succès! Le fichier mp4 a été envoyé à l'endroit à partir du quel ce programme est exécuté.")


def clickaudio():
   video_info = youtube_dl.YoutubeDL().extract_info(
      url=textentry.get(), download=False
   )
   filename = f"{video_info['title']}.mp3"
   options = {
      'format': 'bestaudio/best',
      'keepvideo': False,
      'outtmpl': filename,
      'postprocessors': [{
         'key': 'FFmpegExtractAudio',
         'preferredcodec': 'mp3',
         'preferredquality': '192',
      }]
   }
   with youtube_dl.YoutubeDL(options) as ydl:
      ydl.download([video_info['webpage_url']])
   textentry.delete(0, END)
   status.set("Succès! Le fichier mp3 a été envoyé à l'endroit à partir du quel ce programme est exécuté.")


Label(window, background="silver").pack()

Label(window, text="Lien Youtube à convertir:", background="silver").pack()

Label(window, background="silver").pack()

textentry = Entry(window, width=60)
textentry.get()
textentry.pack()

Label(window, background="silver").pack()

videobutton = Button(window, text="Convertir en vidéo", width=16, command=clickvideo).pack()

Label(window, background="silver").pack()

audiobutton = Button(window, text="Convertir en audio", width=16, command=clickaudio).pack()

Label(window, background="silver").pack()

status = StringVar()
status.set("Si rien ne se passe, il y a un problème avec le lien (typo ou mauvais lien).")

status_label = Label(window, background="silver", textvariable=status)
status_label.pack()

window.mainloop()

谢谢

【问题讨论】:

  • 您好,控制台会弹出一个闪烁的错误,尝试捕获它并在此处包含错误代码
  • 真的好像没有报错,只是一闪一闪,然后又消失了,没有额外的信息。
  • 从命令提示符启动 exe,然后查看它显示的内容
  • 谢谢巴里! C:\Users\User\PycharmProjects\youtubeconverter\dist\guizmoytc>guizmoytc.exe Traceback(最近一次调用最后一次):文件“guizmoytc.py”,第 2 行,在 ModuleNotFoundError: No module named 'pytube' [6576 ] 执行脚本 guizmoytc 失败

标签: python tkinter pyinstaller executable


【解决方案1】:

问题是 pytube 安装在 pycharm 提供的虚拟环境中,而不是全局 python 版本中,所以在终端中说:

pip install pytube 

*其实是pytube3

然后在您安装库的终端中运行 pyinstaller 代码行,它应该会修复错误。

【讨论】:

  • 是的,我确实在 pycharm venv 上安装了这些模块,而不是在我的计算机上(不是在 python 上?)好吧,我将 pytube 和 youtube-dl 安装在与我的 python 相同的位置。安装成功。我从我的 pycharm 文件中重新运行了 pyinstaller。我得到了exe文件。我尝试从命令中打开它,现在我得到了这个: C:\Users\User\PycharmProjects\youtubeconverter\dist>guizmoytc.exe C:\Users\User\PycharmProjects\youtubeconverter\dist> 5 秒后,''致命错误未能执行脚本 guizmoytc''
  • 我是否将模块安装在正确的位置?我必须安装我的python所在的位置还是pycharm所在的位置?
  • 好吧,对不起,实际上我使用的是不同的方法,这是我现在使用与之前相同的方法时遇到的错误:
  • Traceback (most recent call last): File "guizmoytc.py", line 2, in <module> File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module exec(bytecode, module.__dict__) File "pytube\__init__.py", line 16, in <module> File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module exec(bytecode, module.__dict__)
  • File "pytube\streams.py", line 17, in <module> File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module exec(bytecode, module.__dict__) File "pytube\extract.py", line 7, in <module> ImportError: cannot import name 'quote' from 'pytube.compat' (C:\Users\User\PycharmProjects\youtubeconverter\dist\guizmoytc\pytube\compat.pyc) [9596] Failed to execute script guizmoytc
猜你喜欢
  • 1970-01-01
  • 2019-08-15
  • 1970-01-01
  • 1970-01-01
  • 2013-03-14
  • 1970-01-01
  • 2017-10-04
  • 2019-08-07
  • 2016-12-24
相关资源
最近更新 更多