]> jfr.im git - yt-dlp.git/commitdiff
Fix `get_executable_path` (#117)
authorshirt-dev <redacted>
Thu, 25 Feb 2021 22:58:02 +0000 (17:58 -0500)
committerGitHub <redacted>
Thu, 25 Feb 2021 22:58:02 +0000 (04:28 +0530)
Authored-by: shirtjs <redacted>
yt_dlp/utils.py

index 0dbb8546737c4a56dec382f33c23456f4e8d8637..12bc637f853c9ba8f9c5038609176a11218e3187 100644 (file)
@@ -5945,9 +5945,13 @@ def make_dir(path, to_screen=None):
 
 
 def get_executable_path():
-    path = os.path.dirname(sys.argv[0])
-    if os.path.basename(sys.argv[0]) == '__main__':  # Running from source
-        path = os.path.join(path, '..')
+    from zipimport import zipimporter
+    if hasattr(sys, 'frozen'):  # Running from PyInstaller
+        path = os.path.dirname(sys.executable)
+    elif isinstance(globals().get('__loader__'), zipimporter):  # Running from ZIP
+        path = os.path.join(os.path.dirname(__file__), '../..')
+    else:
+        path = os.path.join(os.path.dirname(__file__), '..')
     return os.path.abspath(path)