mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-22 06:00:00 +00:00
Restore LD_LIBRARY_PATH when using PyInstaller (#4666)
Authored by: Lesmiscore
This commit is contained in:
parent
da4db748fa
commit
82ea226c61
1 changed files with 25 additions and 2 deletions
|
@ -840,12 +840,35 @@ class Popen(subprocess.Popen):
|
||||||
else:
|
else:
|
||||||
_startupinfo = None
|
_startupinfo = None
|
||||||
|
|
||||||
def __init__(self, *args, text=False, **kwargs):
|
@staticmethod
|
||||||
|
def _fix_pyinstaller_ld_path(env):
|
||||||
|
"""Restore LD_LIBRARY_PATH when using PyInstaller
|
||||||
|
Ref: https://github.com/pyinstaller/pyinstaller/blob/develop/doc/runtime-information.rst#ld_library_path--libpath-considerations
|
||||||
|
https://github.com/yt-dlp/yt-dlp/issues/4573
|
||||||
|
"""
|
||||||
|
if not hasattr(sys, '_MEIPASS'):
|
||||||
|
return
|
||||||
|
|
||||||
|
def _fix(key):
|
||||||
|
orig = env.get(f'{key}_ORIG')
|
||||||
|
if orig is None:
|
||||||
|
env.pop(key, None)
|
||||||
|
else:
|
||||||
|
env[key] = orig
|
||||||
|
|
||||||
|
_fix('LD_LIBRARY_PATH') # Linux
|
||||||
|
_fix('DYLD_LIBRARY_PATH') # macOS
|
||||||
|
|
||||||
|
def __init__(self, *args, env=None, text=False, **kwargs):
|
||||||
|
if env is None:
|
||||||
|
env = os.environ.copy()
|
||||||
|
self._fix_pyinstaller_ld_path(env)
|
||||||
|
|
||||||
if text is True:
|
if text is True:
|
||||||
kwargs['universal_newlines'] = True # For 3.6 compatibility
|
kwargs['universal_newlines'] = True # For 3.6 compatibility
|
||||||
kwargs.setdefault('encoding', 'utf-8')
|
kwargs.setdefault('encoding', 'utf-8')
|
||||||
kwargs.setdefault('errors', 'replace')
|
kwargs.setdefault('errors', 'replace')
|
||||||
super().__init__(*args, **kwargs, startupinfo=self._startupinfo)
|
super().__init__(*args, env=env, **kwargs, startupinfo=self._startupinfo)
|
||||||
|
|
||||||
def communicate_or_kill(self, *args, **kwargs):
|
def communicate_or_kill(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue