liuyuqi-dellpc 1 year ago
parent
commit
23a6219be3
3 changed files with 13 additions and 2 deletions
  1. 2 1
      client.py
  2. 2 1
      fgh/config.py
  3. 9 0
      fgh/utils/frozen_dir.py

+ 2 - 1
client.py

@@ -9,6 +9,7 @@
 
 
 import os,sys,re
 import os,sys,re
 import argparse
 import argparse
+from fgh.utils.frozen_dir import get_app_path
 
 
 class Client:
 class Client:
     help_str ="""
     help_str ="""
@@ -32,7 +33,7 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
 
 
     def read_config(self):
     def read_config(self):
         import dotenv
         import dotenv
-        current_dir = os.path.dirname(sys.executable)
+        current_dir = get_app_path()
         dotenv.load_dotenv(os.path.join(current_dir, '.env'))
         dotenv.load_dotenv(os.path.join(current_dir, '.env'))
         fgit_host = os.getenv('FGH_HOST')
         fgit_host = os.getenv('FGH_HOST')
         try:
         try:

+ 2 - 1
fgh/config.py

@@ -9,9 +9,10 @@
 
 
 import os, sys
 import os, sys
 from dotenv import load_dotenv
 from dotenv import load_dotenv
+from fgh.utils.frozen_dir import get_app_path
 
 
 if os.path.exists('.env'):
 if os.path.exists('.env'):
-    app_path = os.path.dirname(os.path.dirname(sys.executable))
+    app_path =  get_app_path()
     load_dotenv(os.path.join(app_path, '.env'), verbose=True)
     load_dotenv(os.path.join(app_path, '.env'), verbose=True)
 
 
 class BaseConfig:
 class BaseConfig:

+ 9 - 0
fgh/utils/frozen_dir.py

@@ -0,0 +1,9 @@
+import sys  
+import os  
+   
+def get_app_path() -> str:  
+    """Returns the base application path."""  
+    if hasattr(sys, 'frozen'):  
+        # Handles PyInstaller  
+        return os.path.dirname(sys.executable)  #使用 pyinstaller 打包后的 exe 目录  
+    return os.path.dirname(os.path.dirname(os.path.dirname(__file__))) # 没打包前的py目录