-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Labels
kind/bugSomething isn't working as expectedSomething isn't working as expectedstatus/triageThis issue needs to be triagedThis issue needs to be triaged
Description
Description
I am using Anaconda with the auto_activate_base option disabled (i.e., conda config --set auto_activate_base false), so that Conda is only active when I've explicitly activated it. After activating and then deactivating a Conda environment, this leads to an edge case that causes incorrect behavior in the poetry env use command:
- Before activating the environment:
- System Python is first in the path.
- The CONDA_PREFIX variable is unset.
- Poetry correctly assumes that a virtualenv is not active, and creates a local venv.
- After running
conda activate $HOME/envs/foo:- $HOME/envs/foo is first in the path.
- CONDA_PREFIX is set to $HOME/envs/foo.
- Poetry correctly assumes that $HOME/envs/foo is active and uses it.
- After running
conda deactivate:- System Python takes precedence in PATH.
- CONDA_PREFIX is set, but its value is an empty string (!).
- Because CONDA_PREFIX is set (but empty), Poetry thinks a venv is active.
poetry env usetries to runpythonwith an empty prefix, but cannot findpythonin the path and fails.
The problem is due to
poetry/src/poetry/utils/env/env_manager.py
Line 217 in 0e02be7
| in_venv = env_prefix is not None and conda_env_name != "base" |
Workarounds
Manually run unset CONDA_PREFIX after conda deactivate.
Poetry Installation Method
other
Operating System
Ubuntu 20.04.3
Poetry Version
Poetry (version 2.3.2)
Poetry Configuration
(note: `$USER` in the below is not literal, but redacts my actual username from the server)
cache-dir = "/home/$USER/.cache/pypoetry"
data-dir = "/home/$USER/.local/share/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = false
keyring.enabled = true
python.installation-dir = "{data-dir}/python" # /home/$USER/.local/share/pypoetry/python
repositories.nlu_artifactory.url = "REDACTED_URL"
repositories.nlu_artifactory_upload.url = "REDACTED_URL"
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /home/$USER/.cache/pypoetry/virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = falsePython Sysconfig
See attached: sysconfig.txt
Example pyproject.toml
Poetry Runtime Logs
Log from running poetry -vvv env use /path/to/python3.13 after activating and deactivating the Conda environment is attached: poetry_env_use.log
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't working as expectedSomething isn't working as expectedstatus/triageThis issue needs to be triagedThis issue needs to be triaged