We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
First search registry Why? Because this is a reliable source of truth. It will never contain duplicates. Will always contain latest & accurate information. It can point to Conda environments, and we can search for conda from the path provided in registry.
Search virtualenvwrapper Why? Because there's a specific location where these are stored. It will never contain duplicates, no symlinks. If the envs in the special location are not pipenv, they they must be virtualenvwrapper. & nothing else.
Search pyenv Why? Because there's a specific location where these are stored. It will never contain duplicates, no symlinks.
Homebrew Why? Because there's a specific location where these are stored. It will contain symlinks, but they are in known locations.
Conda Why? Its impossible for environments to be mistakenly identified as conda. Its either a conda env or not. But this is done after pyenv and windows registry as both of those can also contain conda.
Windows Store This is done after Registry.
Finally go through all known directories where environments can be found. E.g. /usr/bin, /usr/local/bin, /opt, etc & look for Python environments. These environments can only be one of
/usr/bin
/usr/local/bin
/opt
At every stage we need to ensure the subsequent search does not try to process and environment that was already processed in a previous step. This way we avoid duplicates. Some of the above steps can definitely be done in parallel.
OS
Limitations
PythonCore
ContinuumAnalytics
HKLM/Software
HKCU/Software
Pseduo code for algorithm
for company of [PythonCore, ContinuumAnalytics]: for each key in [HKLM, HKCU]: for each installed_version in `<key>/Software/Python/<company>` / installed_version are values like 3.12, 3.10, 3.9, etc install_key = `<key>/Software/Python/<company>/<installed_version>InstallPath` env_path = `install_key/(Default)` exe = `install_key/(ExecutablePath)` if company == PythonCore and `exe` exists on disc: version = `install_key/(Version)` / SysVersion contains only first 2 parts of version display_name = `install_key/(DisplayName)` 👍 track this environment else if company == ContinuumAnalytics and `exe` exists on disc: We treat this as a conda env 👍 Now use `conda` algorithm to get all conda environments under the directory `env_path`.
for each directory under `<home>/AppData/Local/Microsoft/WindowsApps`: if directory does not start with `PythonSoftwareFoundation.Python.`: continue if `python.exe` does not exists in the directory: continue app_model_key = `HKCU/Software/Classes/Local Settings/Software/Microsoft/Windows/CurrentVersion/AppModel`; package_name = `<app_model_key>/SystemApData/<directory name>/Schemas/(PackageFullName)` key = `<app_model_key>/Repository/Packages/<package_name>` env_path = `<key>/(PackageRootFolder)` display_name = `<key>/(DisplayName)` exe = `python.exe` / No way to get the full version information. 👍 track this environment
Notes
homebrew_dir = find this folder (either `HOMEBREW_PREFIX` or default to directory defined here https://docs.brew.sh/Installation) for each file under `<homebrew_dir>/bin`: if we have a python executable and its a symlink, then proceed if not, then skip this file resolve the symlink and verify the file is in one of the known homebrew directories. if not, then skip this file Extract the version from the file path. Compute the env_path by extracting the version information. The env_path is known directories on MacOS (Intel & Silicon) and Linux.
envs
.condarc
environments.txt
env
<conda install folder>/envs
conda info --json
<conda install folder>/conda-meta/conda-<version>.json
~/.pyenv/versions/<conda install version>
conda-meta\<package name>-<version>.json
conda
conda-meta
conda update conda
conda-meta\history
# cmd: /Users/donjayamanne/.pyenv/versions/miniconda3-latest/bin/conda create -n myenv python=3.10
history
-p
What if conda is installed in some custom locations that we have no idea about? In such cases the assumption is that the environments.txt file will contain an entry to the base env. Using that information we can get the conda directory and get the conda exe and version info.
Even if environments.txt file is empty, we will look for environments in known locations and from there we can find the conda install folder (recall history file).
What if we have a custom conda env created in current workspace folder, and we do not know where Conda is installed? In such cases we can just inspect the conda-meta/history file in the conda env folder and get the conda installation folder.
conda-meta/history
How do we generate command to run Python in an environment? If the Conda env is in the envs folder, then use <conda exe> -n <env name> python. If the Conda env is the root (base) folder, then use <conda exe> -n base python. For all other cases use <conda exe> -p <fully qualified path to folder> python.
<conda exe> -n <env name> python
<conda exe> -n base python
<conda exe> -p <fully qualified path to folder> python
/ Step 1 / Get a list of all known directories where conda environments can be found / 1. environments.txt file / 2. .condarc file / 3. Other known locations / Step 2 / We hardcode some of the commonly known install directories of conda, miniconda, miniforge, etc for all platforms. for each known_install_folder in [<home>/anaconda3, <home>/miniconda3, etc]: conda_exe = `<known_install_folder>/bin/conda` (windows is slightly different) conda_version = `<known_install_folder>/conda_meta/conda-<version>.json` python_exe = `<known_install_folder>/bin/python` (windows is slightly different) python_version = `<known_install_folder>/conda_meta/conda-<version>.json` / Step 2.1 / We now have conda exe, version, default python information / Conda run command is computed as `[<fully qualified path to conda_exe>, run, -n, <name> python]` for each env in `<known_install_folder>/envs`: / env is a conda environment / Find python exe and version in the conda-meta directory / If python is not found, then this is a conda env without Python. / These are named environments that are activated (run) using the `-n` option. / Previously we captured a list of all known conda envs / Go through those one by one and inspect the conda-meta/history file / And check whether that env was created by this current conda installation / If so, then associate that env with this conda installation / Next remove that env folder from the list captured in step 1. / Step 3 / Finally go through all of the remaining conda envs that were captured in step 1 / & did not get removed by step 2.1. / Go into the env folder one by one / Inspect the conda-meta/history file and try to find the installation location of the conda by parsing the `cmd:` line. / If we find a conda installation, then process that folder as we did inside step 2.1
versions
pyenv
/opt/hombrew/bin/pyenv
/usr/local/bin/pyenv
/opt/homebrew/Cellar/pyenv/2.4.0/libexec/pyenv
/usr/local/Cellar/pyenv/2.4.1/libexec/pyenv
Conda:
Virtual Envs:
pyvenv.cfg
~/.pyenv/versions
~/.pyenv/<python version>/envs
Commands used to run Python:
<fully qualified python exe>
for each dir in pyenv directory: if dir is a conda installation folder: / Pass this onto the conda algorithm continue version = extract version from folder name env_path = the directory itself if <dir>/pyvenv.cfg exists: / This is a virtual env in pyenv else / This is a regulary pyenv installation
.project
.pyvenv.cfg
virtualenvwrapper
Pipfile
Pipfile.lock
for each dir in globally known directories: if `.project` file exists in the directory: proceed if the path in the `.project` file contains a `Pipfile` file: / This is a pipenv environment version = extracted from `.pyvenv.cfg` file
WORKON_HOME
~/.virtualenvs
pipenv
for each dir in $WORKON_HOME: if this is not a pipenv environment: proceed if `.project` file exists in the directory: / This is a virtualenvwrapper version = extracted from `.pyvenv.cfg` file
for each dir in $WORKON_HOME: version = extracted from `.pyvenv.cfg` file
bin/scripts