@@ -8,36 +8,27 @@ def pip_import_string(python_exe):
88 cmd = [
99 python_exe ,
1010 "-c" ,
11- "import pip; assert int (pip.__version__.split('.')[0]) <= 9 "
11+ "import pip; print (pip.__version__) "
1212 ]
13- p = os_utils .popen (cmd ,stdout = os_utils .pipe , stderr = os_utils .pipe )
14- p .communicate ()
13+ p = os_utils .popen (cmd , stdout = os_utils .pipe , stderr = os_utils .pipe )
14+ stdout , stderr = p .communicate ()
15+ pip_version = stdout .decode ('utf-8' ).strip ()
16+ pip_major_version = int (pip_version .split ('.' )[0 ])
17+ pip_minor_version = int (pip_version .split ('.' )[1 ])
18+
1519 # Pip moved its internals to an _internal module in version 10.
1620 # In order to be compatible with version 9 which has it at at the
1721 # top level we need to figure out the correct import path here.
18- if p . returncode == 0 :
22+ if pip_major_version == 9 :
1923 return 'from pip import main'
24+ # Pip changed their import structure again in 19.3
25+ # https://github.com/pypa/pip/commit/09fd200
26+ elif pip_major_version >= 19 and pip_minor_version >= 3 :
27+ return 'from pip._internal.main import main'
2028 else :
2129 return 'from pip._internal import main'
2230
2331
24- def pip_runner_string (python_exe ):
25- os_utils = OSUtils ()
26- cmd = [
27- python_exe ,
28- "-c" ,
29- "import pip; assert (int(pip.__version__.split('.')[0]) <= 19 and int(pip.__version__.split('.')[1]) < 3)"
30- ]
31- p = os_utils .popen (cmd , stdout = os_utils .pipe , stderr = os_utils .pipe )
32- p .communicate ()
33- # Pip changed main to be a module instead of a function from 19.3
34- # and added a separate main function within the main module.
35- if p .returncode == 0 :
36- return 'import sys; %s; sys.exit(main(%s))'
37- else :
38- return 'import sys; %s; sys.exit(main.main(%s))'
39-
40-
4132if os .name == 'nt' :
4233 # windows
4334 # This is the actual patch used on windows to prevent distutils from
0 commit comments