使用Python lyrics_extractor库时持续出现Illegal instruction (core dumped)错误求助
Illegal instruction (core dumped)错误并恢复Tkinter程序运行 先确保Tkinter窗口正常运行
先把和lyrics_extractor相关的代码暂时注释或移除,先验证基础的Tkinter窗口功能是否正常。下面是一个满足你需求的基础Tkinter示例,能正常打开窗口并提示输入歌曲名称:
import tkinter as tk from tkinter import messagebox def get_lyrics(): song_name = entry.get().strip() if not song_name: messagebox.showwarning("提示", "请输入歌曲名称") return # 这里后续可以替换为修复后的歌词提取逻辑 messagebox.showinfo("信息", f"准备提取歌曲《{song_name}》的歌词...") # 创建主窗口 root = tk.Tk() root.title("歌词提取工具") root.geometry("400x150") # 输入框和按钮 label = tk.Label(root, text="请输入歌曲名称:") label.pack(pady=10) entry = tk.Entry(root, width=40) entry.pack(pady=5) button = tk.Button(root, text="提取歌词", command=get_lyrics) button.pack(pady=10) root.mainloop()
运行这段代码,应该能正常弹出窗口,输入歌曲名后点击按钮会有对应的提示,先确保这部分没问题。
处理lyrics_extractor的Illegal instruction错误
这个错误通常是因为库的预编译二进制包使用了你的CPU不支持的指令集,或者依赖环境损坏导致的,按以下步骤排查:
回滚到之前可用的版本
之前程序能运行,说明某个旧版本是兼容的,先卸载当前版本,再安装旧版本:pip uninstall -y lyrics_extractor # 尝试安装较早的版本,比如0.1.2(可根据实际情况调整) pip install lyrics_extractor==0.1.2从源码编译安装
如果预编译包有指令集问题,尝试从源码安装,让库适配你的CPU:pip uninstall -y lyrics_extractor pip install git+https://github.com/akashrchandran/lyrics-extractor.git --no-binary :all:重建虚拟环境
若虚拟环境中的依赖文件损坏,新建一个干净的虚拟环境再重新安装所有依赖:# 假设用venv,根据你的环境调整 python -m venv new_env # 激活虚拟环境(Windows:new_env\Scripts\activate;Linux/macOS:source new_env/bin/activate) pip install tkinter lyrics_extractor替换为替代库
如果lyrics_extractor始终无法解决问题,可以换用更稳定的lyricsgenius库,示例整合代码:import tkinter as tk from tkinter import messagebox import lyricsgenius
GENIUS_TOKEN = "your_api_token_here"
genius = lyricsgenius.Genius(GENIUS_TOKEN)
def get_lyrics():
song_name = entry.get().strip()
if not song_name:
messagebox.showwarning("提示", "请输入歌曲名称")
return
try:
song = genius.search_song(song_name)
if song:
messagebox.showinfo(f"《{song_name}》歌词", song.lyrics[:1000] + "\n...") # 截取部分显示
else:
messagebox.showinfo("结果", "未找到该歌曲的歌词")
except Exception as e:
messagebox.showerror("错误", f"提取失败:{str(e)}")
root = tk.Tk()
root.title("歌词提取工具")
root.geometry("400x150")
label = tk.Label(root, text="请输入歌曲名称:")
label.pack(pady=10)
entry = tk.Entry(root, width=40)
entry.pack(pady=5)
button = tk.Button(root, text="提取歌词", command=get_lyrics)
button.pack(pady=10)
root.mainloop()
内容的提问来源于stack exchange,提问作者user24038079

