Reputation:
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
Upvotes: 2
Views: 11275
Reputation: 7744
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']
Upvotes: 6