diff -r b9404639a18c Lib/venv/__init__.py --- a/Lib/venv/__init__.py Wed Jan 11 00:07:40 2017 +0100 +++ b/Lib/venv/__init__.py Tue Jan 10 17:40:04 2017 -0800 @@ -57,13 +57,20 @@ """ env_dir = os.path.abspath(env_dir) context = self.ensure_directories(env_dir) - self.create_configuration(context) + self.create_configuration(context, force_no_site=True) self.setup_python(context) if self.with_pip: self._setup_pip(context) if not self.upgrade: self.setup_scripts(context) self.post_setup(context) + if self.system_site_packages: + # Recreate venv config file. + self.create_configuration(context) + # Remove installed site-packages files. + shutil.rmtree(context.libpath) + # Recreate empty site-packages directory. + os.mkdir(context.libpath) def clear_directory(self, path): for fn in os.listdir(path): @@ -115,6 +122,7 @@ 'python%d.%d' % sys.version_info[:2], 'site-packages') context.inc_path = path = os.path.join(env_dir, incpath) + context.libpath = libpath create_if_needed(path) create_if_needed(libpath) # Issue 21197: create lib64 as a symlink to lib on 64-bit non-OS X POSIX @@ -129,7 +137,7 @@ create_if_needed(binpath) return context - def create_configuration(self, context): + def create_configuration(self, context, force_no_site=False): """ Create a configuration file indicating where the environment's Python was copied from, and whether the system site-packages should be made @@ -141,7 +149,7 @@ context.cfg_path = path = os.path.join(context.env_dir, 'pyvenv.cfg') with open(path, 'w', encoding='utf-8') as f: f.write('home = %s\n' % context.python_dir) - if self.system_site_packages: + if self.system_site_packages and not force_no_site: incl = 'true' else: incl = 'false'