如何使用 Python 查找 Pycharm 的版本

How to find Pycharm's Version Using Python

I have a program that gets version from (selenium, python and chrome) from my system and compares it with the latest version online.

This is the code to get pythons version from my system

    pythonVersion = platform.python_version()
    finalVersion = "Python " + pythonVersion

Now my main problem is trying to get Pycharms version using code. It would be helpful if anyone has any idea on how to do it

我已经对其进行了研究,但我找不到 solution/plugin 可以在几行中获得 IDE 的版本。这是预料之中的,因为 python 无法知道正在使用什么 IDE。

例如, Pycharm.getVersion() # This is not possible.

获取 Pycharm 版本的方法之一是直接查看安装文件。

在我的目录中,我安装了 PyCharm:

C:\Program Files\JetBrains\PyCharm 2019.3

其中应该有一个名为 product-info.json 的文件。看起来像这样:

{
  "name": "PyCharm",
  "version": "2019.3.3",
  "buildNumber": "193.6494.30",
  "productCode": "PY",
  "svgIconPath": "bin/pycharm.svg",
  "launch": [
    {
      "os": "Windows",
      "launcherPath": "bin/pycharm64.exe",
      "javaExecutablePath": "jbr/bin/java.exe",
      "vmOptionsFilePath": "bin/pycharm64.exe.vmoptions"
    }
  ]
}

所以你可以做的是,在你的代码中定义这个 JSON 文件的 absolute/relative 路径,然后通过 data['version'] 访问版本,其中数据保存 JSON 个对象。

执行以下操作:

import json

with open('/Applications/PyCharm\ CE.app/Contents/Resources/product-info.json') as json_file:
    data = json.load(json_file)
    version = data['version']