简体   繁体   中英

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

I have researched into it but I was unable to find a solution/plugin that will get the version of the IDE in few lines. This is expected since python has no way of knowing what IDE is being used.

For example, Pycharm.getVersion() # This is not possible.

One of the ways how you can get the version of Pycharm is to look directly in the installation file.

In mine, I have installed PyCharm in the following Dir:

C:\\Program Files\\JetBrains\\PyCharm 2019.3

And within that there should be a file called product-info.json . Looks like this:

{
  "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"
    }
  ]
}

So what you can do is, define an absolute/relative path to this JSON file and within your code and simply access the version by doing data['version'] , where data holds the JSON objects.

Do the following:

import json

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM