diff --git a/poetry/utils/env.py b/poetry/utils/env.py index 121bbef32c3..d9c502f2946 100644 --- a/poetry/utils/env.py +++ b/poetry/utils/env.py @@ -286,7 +286,13 @@ def get(self, reload=False): # type: (bool) -> Env python_minor = env["minor"] # Check if we are inside a virtualenv or not - in_venv = os.environ.get("VIRTUAL_ENV") is not None + # Conda sets CONDA_PREFIX in its envs, see + # https://github.com/conda/conda/issues/2764 + env_prefix = os.environ.get("VIRTUAL_ENV", os.environ.get("CONDA_PREFIX")) + conda_env_name = os.environ.get("CONDA_DEFAULT_ENV") + # It's probably not a good idea to pollute Conda's global "base" env, since + # most users have it activated all the time. + in_venv = env_prefix is not None and conda_env_name != "base" if not in_venv or env is not None: # Checking if a local virtualenv exists @@ -315,8 +321,8 @@ def get(self, reload=False): # type: (bool) -> Env return VirtualEnv(venv) - if os.environ.get("VIRTUAL_ENV") is not None: - prefix = Path(os.environ["VIRTUAL_ENV"]) + if env_prefix is not None: + prefix = Path(env_prefix) base_prefix = None else: prefix = Path(sys.prefix)