我有一個PyInstaller的跨平臺GUI界面。我想檢查已安裝的PyInstaller的版本。用戶提供PyInstaller的安裝文件夾。我可以通過命令行python pyinstaller --version
執行此操作,但是這會在Windows上打開我想要避免的命令提示符。有沒有一種方法可以訪問Python模塊中的get_version()函數,而不是正在運行的應用程序所在的路徑?或者,如何防止在Windows上啓動命令提示符,同時保持我的應用程序的跨平臺兼容性。從用戶指定的目錄中導入一個python模塊?
這裏是我到目前爲止的代碼:
def pyversion(installdir):
flags=[]
flags.append(sys.executable)
pylocation = os.path.join(installdir, 'pyinstaller.py')
flags.append(pylocation)
flags.append('--version')
p = subprocess.Popen(flags,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out,err = p.communicate()
return float(out.strip()[:3])
如果GUI什麼正在安裝'pyinstaller'的同一個python運行,然後你可以'從Pyinstaller import get_version; version = get_version()'。或修改'sys.path'從目錄中導入假設版本兼容 – jfs