我有一个 PyInstaller 的跨平台 GUI 界面。我想检查安装的 PyInstaller 版本。用户提供 PyInstaller 的安装文件夹。我可以通过命令行 python pyinstaller --version 执行此操作,但这会在我想避免的 Windows 上打开命令提示符。有没有办法在与正在运行的应用程序不在同一路径的 Python 模块中访问 get_version() 函数?或者,如何防止命令提示符在 Windows 上启动,同时保持我的应用程序的跨平台兼容性。
到目前为止,这是我的代码:
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])
请您参考如下方法:
my_path = "some/path/blah"
os.path.insert(0,my_path)
import my_custom_module
你只需要在导入之前将它添加到路径中......或者我不明白你在问什么
