2

我有一个 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])
4

1 回答 1

3
my_path = "some/path/blah"
os.path.insert(0,my_path)
import my_custom_module

您只需要在导入之前将其添加到路径中...或者我不明白您在问什么

于 2013-08-21T18:40:45.853 回答