简体   繁体   English

如何在某些操作系统上禁用Python程序?

[英]How can I disable use of Python programs on certain operating systems?

I wish to disable the ability to run my program on certain Windows operating systems to prevent certain issues I can't replicate in newer versions. 我希望禁用在某些Windows操作系统上运行程序的功能,以防止某些无法在较新版本中复制的问题。 I would like to prevent running it on Windows XP, Vista, and eventually, 7. 我想防止在Windows XP,Vista以及最终版本7上运行它。

How can I achieve this? 我该如何实现? For a little while I used an if statement with _platform but that did not work well or efficiently. 有一阵子,我使用了带有_platform的if语句,但是效果不佳或效率很高。

You can use sys.getwindowsversion : 您可以使用sys.getwindowsversion

import sys

ver = sys.getwindowsversion()
if ver.major == 6 and ver.minor == 1:
    print('Windows 7')
elif ver.major == 6 and ver.minor == 0:
    print('Windows Vista')
elif ver.major == 5 and ver.minor == 0:
    print('Windows XP')

Version numbers taken from this page . 从此页面获取的版本号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不同操作系统上的Python程序 - Python programs on different Operating Systems 如何使用 python 卸载程序? - How can I use python to uninstall programs? 如何使用Python连续读取基于Linux的操作系统的CPU温度? - How can I get a continuous reading of CPU temperature for Linux based operating systems using Python? Python和不同的操作系统 - Python and different Operating Systems 如何在多个操作系统中手动告诉Python在脚本本身中使用哪个版本? - How do you manually tell Python which version to use in the script itself, across multiple operating systems? 如何确保 Python qt 应用程序在所有操作系统上都是屏幕可读的 - how can ensure that a Python qt application is screen readable on all operating systems 如何在Python中区分“Android”与其他“Linux”操作系统? - How to distinguish “Android” from other “Linux” operating systems in Python? 如何分发 python 程序? - How can I distribute python programs? Python:如何使用多重处理来加快对类实例的操作? - Python: How can i use multiprocessing to speed up operating on class instances? 如何使用 python 控制多个并发命令行程序? - How can I use python to control multiple concurrant command line programs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM