How to find Pycharm's Version Using Python

别来无恙 提交于 2020-04-18 05:43:29

问题


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


回答1:


Good question. 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 path to this JSON file and within your code 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']


来源:https://stackoverflow.com/questions/60607002/how-to-find-pycharms-version-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!