Skip to content

Commit

Permalink
Merge pull request #4319 from pypa/bugfix/4315
Browse files Browse the repository at this point in the history
Correctly populate the system python path
  • Loading branch information
frostming authored Jun 5, 2020
2 parents 76e55df + 69c5cea commit 1a6e030
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/4315.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that incorrect Python path will be used when ``--system`` flag is on.
2 changes: 2 additions & 0 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Environment(object):
def __init__(
self,
prefix=None, # type: Optional[str]
python=None, # type: Optional[str]
is_venv=False, # type: bool
base_working_set=None, # type: pkg_resources.WorkingSet
pipfile=None, # type: Optional[Union[tomlkit.toml_document.TOMLDocument, TPipfile]]
Expand All @@ -51,6 +52,9 @@ def __init__(
self._modules = {'pkg_resources': pkg_resources, 'pipenv': pipenv}
self.base_working_set = base_working_set if base_working_set else BASE_WORKING_SET
prefix = normalize_path(prefix)
self._python = None
if python is not None:
self._python = vistir.compat.Path(python).absolute().as_posix()
self.is_venv = is_venv or prefix != normalize_path(sys.prefix)
if not sources:
sources = []
Expand Down Expand Up @@ -267,9 +271,15 @@ def script_basedir(self):
def python(self):
# type: () -> str
"""Path to the environment python"""
py = vistir.compat.Path(self.script_basedir).joinpath("python").absolute().as_posix()
if self._python is not None:
return self._python
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()
py = vistir.compat.Path(sys.executable).as_posix()
self._python = py
return py

@cached_property
Expand Down
6 changes: 4 additions & 2 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,14 @@ def get_environment(self, allow_global=False):
is_venv = is_in_virtualenv()
if allow_global and not is_venv:
prefix = sys.prefix
python = sys.executable
else:
prefix = self.virtualenv_location
python = None
sources = self.sources if self.sources else [DEFAULT_SOURCE]
environment = Environment(
prefix=prefix, is_venv=is_venv, sources=sources, pipfile=self.parsed_pipfile,
project=self
prefix=prefix, python=python, is_venv=is_venv, sources=sources,
pipfile=self.parsed_pipfile, project=self
)
pipenv_dist = get_pipenv_dist(pkg="pipenv")
if pipenv_dist:
Expand Down

0 comments on commit 1a6e030

Please sign in to comment.