File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -796,6 +796,7 @@ def venv(known_paths):
796796 if candidate_conf :
797797 virtual_conf = candidate_conf
798798 system_site = "true"
799+ version = None
799800 # Issue 25185: Use UTF-8, as that's what the venv module uses when
800801 # writing the file.
801802 with open (virtual_conf , encoding = 'utf-8' ) as f :
@@ -808,6 +809,28 @@ def venv(known_paths):
808809 system_site = value .lower ()
809810 elif key == 'home' :
810811 sys ._home = value
812+ elif key == 'version' :
813+ version = value
814+
815+ if version :
816+ try :
817+ major , minor = map (int , version .split ("." )[:2 ])
818+ except ValueError :
819+ major , minor = None
820+
821+ if (
822+ major == sys .version_info .major
823+ and minor is not None
824+ and minor != sys .version_info .minor
825+ and not hasattr (sys , "_venv_version_warning_emitted" )
826+ ):
827+ _warn (
828+ f"This virtual environment was created for Python { major } .{ minor } , "
829+ f"but the current interpreter is Python "
830+ f"{ sys .version_info .major } .{ sys .version_info .minor } . "
831+ "Consider running `python -m venv --upgrade` to update the environment." ,
832+ RuntimeWarning ,
833+ )
811834
812835 if sys .prefix != site_prefix :
813836 _warn (f'Unexpected value in sys.prefix, expected { site_prefix } , got { sys .prefix } ' , RuntimeWarning )
You can’t perform that action at this time.
0 commit comments