diff --git a/news/4315.bugfix.rst b/news/4315.bugfix.rst new file mode 100644 index 00000000..6b8102b5 --- /dev/null +++ b/news/4315.bugfix.rst @@ -0,0 +1 @@ +Fix a bug that incorrect Python path will be used when ``--system`` flag is on. diff --git a/pipenv/core.py b/pipenv/core.py index 02971f22..9b37ff42 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1946,6 +1946,8 @@ def do_install( # Automatically use an activated virtualenv. if PIPENV_USE_SYSTEM: system = True + if system: + os.environ["PIPENV_USE_SYSTEM"] = "1" # Check if the file is remote or not if remote: click.echo( diff --git a/pipenv/environment.py b/pipenv/environment.py index fbfe9615..db51af74 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -267,7 +267,10 @@ class Environment(object): def python(self): # type: () -> str """Path to the environment python""" - py = vistir.compat.Path(self.script_basedir).joinpath("python").absolute().as_posix() + if os.name == "nt" and not self.is_venv: + py = vistir.compat.Path(self.prefix).joinpath("python").absolute().as_posix() + else: + py = vistir.compat.Path(self.script_basedir).joinpath("python").absolute().as_posix() if not py: return vistir.compat.Path(sys.executable).as_posix() return py