From c07206c18992c1dca401b30a01b9f0fe54a71df5 Mon Sep 17 00:00:00 2001 From: Alberto Sottile Date: Thu, 14 Mar 2019 15:45:55 +0100 Subject: [PATCH] Run mpv subprocess with a system PYTHONPATH env on macOS. youtube-dl relies on system python to run on macOS, but system python cannot be executed in a subprocess created from the frozen python3 executable. This makes youtube-dl unusable from frozen versions of Syncplay on macOS. So, the environment of the mpv subprocess is modified with system PYTHONPATH, allowing the execution of /usr/bin/python (and hence, of youtube-dl) from within the subprocess in frozen executables. Fixes: #228 --- syncplay/players/mplayer.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index 69fa0d2..b1baa6b 100755 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -1,4 +1,5 @@ # coding:utf8 +import ast import os import re import subprocess @@ -10,7 +11,7 @@ import time from syncplay import constants, utils from syncplay.players.basePlayer import BasePlayer from syncplay.messages import getMessage -from syncplay.utils import isWindows +from syncplay.utils import isMacOS, isWindows class MplayerPlayer(BasePlayer): @@ -338,6 +339,20 @@ class MplayerPlayer(BasePlayer): env = os.environ.copy() if 'TERM' in env: del env['TERM'] + # On macOS, youtube-dl requires system python to run. Set the environment + # to allow that version of python to be executed in the mpv subprocess. + if isMacOS(): + try: + pythonLibs = subprocess.check_output(['/usr/bin/python', '-E', '-c', + 'import sys; print(sys.path)'], + text=True, env=dict()) + pythonLibs = ast.literal_eval(pythonLibs) + pythonPath = ':'.join(pythonLibs[1:]) + except: + pythonPath = None + if pythonPath is not None: + env['PATH'] = '/usr/bin:/usr/local/bin' + env['PYTHONPATH'] = pythonPath if filePath: self.__process = subprocess.Popen( call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT,