Force python version in windows

I know how to write a python script to tell the unix browser which version of python to run (#! / Usr / bin / env python3.2), but how to do it on Windows. I will deploy the program through distutils for windows that have both python2.7 and 3.2 installed. I need to get him to use 2.7

Thanks!

+4
source share
1 answer

Even on unix with shebang ( #! ) You do not force which version to run. If the program is not running directly ( ./my.py ) and instead runs as python2 my.py , then Python 2 will be used.

I would suggest that the safest way is to check the version at the beginning of your script and issue with an error message if it does not fit, for example:

 if sys.version_info[:3] < (3,2,0): print('requires Python >= 3.2.0') sys.exit(1) 
+4
source

Source: https://habr.com/ru/post/1381007/


All Articles