diff --git a/pip/commands/install.py b/pip/commands/install.py index 7ddde93c255..12aabcd0b37 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -352,35 +352,45 @@ def run(self, options, args): if options.target_dir: ensure_dir(options.target_dir) - lib_dir = distutils_scheme('', home=temp_target_dir)['purelib'] - - for item in os.listdir(lib_dir): - target_item_dir = os.path.join(options.target_dir, item) - if os.path.exists(target_item_dir): - if not options.upgrade: - logger.warning( - 'Target directory %s already exists. Specify ' - '--upgrade to force replacement.', - target_item_dir - ) - continue - if os.path.islink(target_item_dir): - logger.warning( - 'Target directory %s already exists and is ' - 'a link. Pip will not automatically replace ' - 'links, please remove if replacement is ' - 'desired.', - target_item_dir - ) - continue - if os.path.isdir(target_item_dir): - shutil.rmtree(target_item_dir) - else: - os.remove(target_item_dir) + lib_dir_purelib = distutils_scheme('', home=temp_target_dir)['purelib'] + lib_dir_platlib = distutils_scheme('', home=temp_target_dir)['platlib'] + if os.path.exists(lib_dir_purelib): + self._install_to_target(lib_dir_purelib, options.target_dir, + options) + if os.path.exists(lib_dir_platlib): + self._install_to_target(lib_dir_platlib, options.target_dir, + options) - shutil.move( - os.path.join(lib_dir, item), - target_item_dir - ) shutil.rmtree(temp_target_dir) return requirement_set + + @staticmethod + def _install_to_target(lib_dir, target_dir, options): + for item in os.listdir(lib_dir): + target_item_dir = os.path.join(target_dir, item) + if os.path.exists(target_item_dir): + if not options.upgrade: + logger.warning( + 'Target directory %s already exists. Specify ' + '--upgrade to force replacement.', + target_item_dir + ) + continue + if os.path.islink(target_item_dir): + logger.warning( + 'Target directory %s already exists and is ' + 'a link. Pip will not automatically replace ' + 'links, please remove if replacement is ' + 'desired.', + target_item_dir + ) + continue + if os.path.isdir(target_item_dir): + shutil.rmtree(target_item_dir) + else: + os.remove(target_item_dir) + + shutil.move( + os.path.join(lib_dir, item), + target_item_dir + )