如何使用Python查找Pycharm版本 [英] How to find Pycharm's Version Using Python

查看:609
本文介绍了如何使用Python查找Pycharm版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以从系统中(硒,python和chrome)获取版本,并将其与在线最新版本进行比较.

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

这是从我的系统获取pythons版本的代码

This is the code to get pythons version from my system

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

现在我的主要问题是尝试使用代码获取Pycharms版本.如果有人对如何操作有任何想法,这将很有帮助

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

推荐答案

我已经对其进行了研究,但是我找不到能够在几行中获得IDE版本的解决方案/插件.这是预料之中的,因为python无法知道正在使用什么IDE.

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.

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

获取Pycharm版本的方法之一是直接在安装文件中查找.

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

在我的产品中,我已经在以下目录中安装了PyCharm:

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

C:\ Program Files \ JetBrains \ PyCharm 2019.3

C:\Program Files\JetBrains\PyCharm 2019.3

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

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

因此,您可以做的是,定义此JSON文件的绝对/相对路径,然后在代码内执行data['version']即可访问版本,其中数据保存JSON对象.

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

执行以下操作:

import json

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

这篇关于如何使用Python查找Pycharm版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆