commit c07206c18992c1dca401b30a01b9f0fe54a71df5
Author: Alberto Sottile <alby128@gmail.com>
Date: Thu Mar 14 15:45:55 2019 +0100
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.
This sets PYTHONPATH to a a value determined by running /usr/bin/python and extracting sys.path, as well as hardcoding PATH to /usr/bin:/usr/local/bin.
It seems that Homebrew does install youtube-dl using /usr/bin/python. But youtube-dl can be installed with any installation of Python, e.g. using pip install youtube-dl or by cloning the repository and running python setup.py install. For that matter, it can also be installed at any path; I'd expect Syncplay to respect the existing PATH variable.
In my case, I have youtube-dl installed as /usr/local/bin/youtube-dl, so Syncplay does see it even with the hardcoded PATH. But the shebang points to /usr/local/bin/python3, the copy of Python I installed it with. When mpv invokes it with PYTHONPATH containing a bunch of paths from the system Python 2.7, it naturally fails to start.
It shouldn't be necessary to set PYTHONPATH at all; after all, it's not like you normally have to manually set PYTHONPATH before running youtube-dl. Instead, I believe the original problem this commit was addressing arose from the fact that Syncplay's frozen Python 3 itself sets PYTHONPATH, and this was inadvertently inherited by youtube-dl. A better approach is to simply unset PYTHONPATH before running youtube-dl. (Or for maximum correctness, figure out what the PYTHONPATH environment variable was originally set to before frozen Python overwrote it, but that may be difficult.)
As for PATH, it doesn't seem like frozen Python modifies it, but I guess the desire is to find youtube-dl in /usr/local/bin even though macOS normally runs apps with PATH set to /usr/bin:/bin:/usr/sbin:/sbin (though it's alterable). The goal makes sense, but some users may use other paths, especially (but not only) when not using frozen Python – I normally run Syncplay from terminal. Instead of replacing the entire PATH, Syncplay should probably just add /usr/local to the end of PATH, so the user's paths take precedence. Also, PATH alteration should probably only happen at all when running under frozen Python; the current code enables it whenever isMacOS() returns true. (I normally run Syncplay directly from a Git checkout using python3 syncplayClient.py.)
This sets
PYTHONPATHto a a value determined by running/usr/bin/pythonand extractingsys.path, as well as hardcodingPATHto/usr/bin:/usr/local/bin.It seems that Homebrew does install youtube-dl using
/usr/bin/python. But youtube-dl can be installed with any installation of Python, e.g. usingpip install youtube-dlor by cloning the repository and runningpython setup.py install. For that matter, it can also be installed at any path; I'd expect Syncplay to respect the existingPATHvariable.In my case, I have youtube-dl installed as
/usr/local/bin/youtube-dl, so Syncplay does see it even with the hardcodedPATH. But the shebang points to/usr/local/bin/python3, the copy of Python I installed it with. When mpv invokes it withPYTHONPATHcontaining a bunch of paths from the system Python 2.7, it naturally fails to start.It shouldn't be necessary to set
PYTHONPATHat all; after all, it's not like you normally have to manually setPYTHONPATHbefore runningyoutube-dl. Instead, I believe the original problem this commit was addressing arose from the fact that Syncplay's frozen Python 3 itself setsPYTHONPATH, and this was inadvertently inherited byyoutube-dl. A better approach is to simply unsetPYTHONPATHbefore runningyoutube-dl. (Or for maximum correctness, figure out what thePYTHONPATHenvironment variable was originally set to before frozen Python overwrote it, but that may be difficult.)As for
PATH, it doesn't seem like frozen Python modifies it, but I guess the desire is to find youtube-dl in /usr/local/bin even though macOS normally runs apps withPATHset to/usr/bin:/bin:/usr/sbin:/sbin(though it's alterable). The goal makes sense, but some users may use other paths, especially (but not only) when not using frozen Python – I normally run Syncplay from terminal. Instead of replacing the entirePATH, Syncplay should probably just add/usr/localto the end ofPATH, so the user's paths take precedence. Also,PATHalteration should probably only happen at all when running under frozen Python; the current code enables it wheneverisMacOS()returns true. (I normally run Syncplay directly from a Git checkout usingpython3 syncplayClient.py.)