New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PYTHONPATH fix on macOS actually breaks it depending on configuration #276
Comments
- Only apply when actually running under py2app, as opposed to whenever running on macOS. - Instead of setting PATH to a fully hardcoded value, just append /usr/local/bin if not already present. That way any non-default choices by the user are respected. - Unset PYTHONPATH instead of setting it based on /usr/bin/python's sys.path. mpv or other players could end up invoking any copy of Python, so there's no sensible value to set it to, but it's (normally) fine to leave it blank. The important thing is that we don't keep the value set by py2app, pointing to our own Contents/Resources directory. (It should be safe to change PYTHONPATH at this point without affecting Syncplay's own execution, since Python only checks it at startup.) - Unset other Python environment variables instead of just PYTHONPATH, because py2app sets a number of them (including PYTHONDONTWRITEBYTECODE and PYTHONHOME). - Do the environment variable patchup when starting Syncplay, so it applies to all players rather than just mplayer-based ones. Fixes Syncplay#276.
I am trying to find a fix that would work with:
What I wrote in the commit message still stands, though it is restricted to scenario A). In this scenario, the "environment variable patchup" is needed also when Syncplay is started from the command line. The issue lies in the homebrew build of Scenario B) works out of the box with the current Syncplay and system Python, as the shebang is To fix this issue for scenario C), we would need to add something in our code to identify which version of In summary, I think that the only viable solution for us is to state this issue among the known issues/limitations of Syncplay and advise to use the homebrew version of mpv or to install For the reasons stated above, I am closing this issue now. Please feel free to comment here or reopen it anytime. |
This sets
PYTHONPATH
to a a value determined by running/usr/bin/python
and extractingsys.path
, as well as hardcodingPATH
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. usingpip install youtube-dl
or 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 existingPATH
variable.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 withPYTHONPATH
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 setPYTHONPATH
before 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 unsetPYTHONPATH
before runningyoutube-dl
. (Or for maximum correctness, figure out what thePYTHONPATH
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 withPATH
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 entirePATH
, Syncplay should probably just add/usr/local
to the end ofPATH
, 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 wheneverisMacOS()
returns true. (I normally run Syncplay directly from a Git checkout usingpython3 syncplayClient.py
.)The text was updated successfully, but these errors were encountered: