1414# * limitations under the License.
1515
1616import os
17- import subprocess
1817import re
18+ import sys
19+ import time
20+ import json
1921import urllib
22+ import shutil
2023import tarfile
2124import zipfile
2225import logging
23- from threading import Thread
24- import time
25- import sys
26- from contextlib import closing
2726import platform
2827import tempfile
29- import json
30- import shutil
28+ import subprocess
29+ from threading import Thread
30+ from contextlib import closing
3131
3232from wheel import pep425tags as wheel_tags
3333
4040PLATFORM = sys .platform
4141IS_WIN = (os .name == 'nt' )
4242IS_DARWIN = (PLATFORM == 'darwin' )
43- IS_LINUX = ( PLATFORM == 'linux2 ' )
43+ IS_LINUX = PLATFORM . startswith ( 'linux ' )
4444
4545PROCESS_POLLING_INTERVAL = 0.1
4646
@@ -98,7 +98,8 @@ def run(cmd, suppress_errors=False, suppress_output=False):
9898def wheel (package , requirement_files = False , wheels_path = 'package' ,
9999 excluded_packages = None , wheel_args = None , no_deps = False ):
100100 lgr .info ('Downloading Wheels for {0}...' .format (package ))
101- wheel_cmd = ['pip' , 'wheel' ]
101+ pip_executable = os .path .join (os .path .dirname (sys .executable ), 'pip' )
102+ wheel_cmd = [pip_executable , 'wheel' ]
102103 wheel_cmd .append ('--wheel-dir={0}' .format (wheels_path ))
103104 wheel_cmd .append ('--find-links={0}' .format (wheels_path ))
104105 if no_deps :
@@ -121,6 +122,7 @@ def wheel(package, requirement_files=False, wheels_path='package',
121122 lgr .error ('Could not download wheels for: {0}. '
122123 'Please verify that the package you are trying '
123124 'to wheel is wheelable.' .format (package ))
125+ lgr .error (p .aggr_stdout )
124126 sys .exit (codes .errors ['failed_to_wheel' ])
125127 wheels = get_downloaded_wheels (wheels_path )
126128 excluded_packages = excluded_packages or []
@@ -158,9 +160,10 @@ def install_package(package, wheels_path, virtualenv_path=None,
158160 # install_args = install_args or []
159161
160162 lgr .info ('Installing {0}...' .format (package ))
161-
162- pip_cmd = ['pip' , 'install' ]
163+ pip_executable = os . path . join ( os . path . dirname ( sys . executable ), 'pip' )
164+ pip_cmd = [pip_executable , 'install' ]
163165 if virtualenv_path :
166+ pip_cmd = ['pip' , 'install' ]
164167 pip_cmd [0 ] = os .path .join (
165168 _get_env_bin_path (virtualenv_path ), pip_cmd [0 ])
166169 if requirements_file :
@@ -286,8 +289,11 @@ def _get_env_bin_path(env_path):
286289def check_installed (package , virtualenv ):
287290 """Checks to see if a package is installed within a virtualenv.
288291 """
289- pip_path = os .path .join (_get_env_bin_path (virtualenv ), 'pip' )
290- p = run ('{0} freeze' .format (pip_path ), suppress_output = True )
292+ if virtualenv :
293+ pip_executable = os .path .join (_get_env_bin_path (virtualenv ), 'pip' )
294+ else :
295+ pip_executable = os .path .join (os .path .dirname (sys .executable ), 'pip' )
296+ p = run ('{0} freeze' .format (pip_executable ), suppress_output = True )
291297 if re .search (r'{0}' .format (package ), p .aggr_stdout .lower ()):
292298 lgr .debug ('Package {0} is installed in {1}' .format (
293299 package , virtualenv ))
0 commit comments