diff --git a/src/virtualenv/activation/python/activate_this.py b/src/virtualenv/activation/python/activate_this.py index befe8f405..388e00153 100644 --- a/src/virtualenv/activation/python/activate_this.py +++ b/src/virtualenv/activation/python/activate_this.py @@ -1,7 +1,8 @@ """ Activate virtualenv for current interpreter: -Use exec(open(this_file).read(), {'__file__': this_file}). +import runpy +runpy.run_path(this_file) This can be used when you must use an existing Python interpreter, not the virtualenv bin/python. """ # noqa: D415 @@ -15,7 +16,7 @@ try: abs_file = os.path.abspath(__file__) except NameError as exc: - msg = "You must use exec(open(this_file).read(), {'__file__': this_file})" + msg = "You must use import runpy; runpy.run_path(this_file)" raise AssertionError(msg) from exc bin_dir = os.path.dirname(abs_file)