我尝试使用auto-py-to-exe制作我的 python 脚本的独立可执行文件,它基本上为使用 pyinstaller 创建可执行文件提供了简单的界面,所以我制作了我的 python 脚本的 exe,它是基于控制台的,当我尝试运行 exe我制作了我的脚本,然后控制台打开了一秒钟,然后很快就出现了一堆错误。但是,该脚本在空闲时运行良好。我附上了我收到的错误的屏幕截图。根据我的观察,错误很可能是由于 VLC 模块的导入而发生的,因为在错误跟踪中,您将看到它发生在第 2 行并且我已导入 VLC 的那一行。我还通过更改 VLC 的导入行号来观察。我是一个初学者,所以我需要知道解决方案的步骤。
from bs4 import BeautifulSoup
import vlc
import pafy
import urllib.request
import time
textToSearch = 'tremor dimitri vegas '
query = urllib.parse.quote(textToSearch)
urlq = "https://www.youtube.com/results?search_query=" + query
response = urllib.request.urlopen(urlq)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
track_links=[]
i=0
for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}):
i=i+1
print('https://www.youtube.com' + vid['href'])
track_links.append('https://www.youtube.com' + vid['href'])
if i==2:
break
print()
url = track_links[1]
video = pafy.new(url)
best = video.getbestaudio()
playurl = best.url
ins = vlc.Instance()
player = ins.media_player_new()
code = urllib.request.urlopen(url).getcode()
if str(code).startswith('2') or str(code).startswith('3'):
print('Stream is working and playing song')
else:
print('Stream is dead')
Media = ins.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
player.play()
time.sleep(20)
player.stop()#breaking here just for check purpose
现在这是完整的错误跟踪
`Traceback (most recent call last):
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 149, in _
_init__
File "ctypes\__init__.py", line 348, in __init__
OSError: [WinError 126] The specified module could not be found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "liveyoutbe.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "c:\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\vlc.py", line 207, in <module>
File "site-packages\vlc.py", line 163, in find_lib
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 151, in _
_init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'libvlc.dll'. Most pr
obably this dynlib/dll was not found when the application was frozen.
[6032] Failed to execute script liveyoutbe`