Find the path to the conda executable
()
| 24 | |
| 25 | |
| 26 | def _get_conda_executable(): |
| 27 | """Find the path to the conda executable""" |
| 28 | # Check if there is a conda executable in the same directory as the Python executable. |
| 29 | # This is the case within conda's root environment. |
| 30 | conda = os.path.join(os.path.dirname(sys.executable), 'conda') |
| 31 | if os.path.isfile(conda): |
| 32 | return conda |
| 33 | |
| 34 | # Otherwise, attempt to extract the executable from conda history. |
| 35 | # This applies in any conda environment. |
| 36 | R = re.compile(r"^#\s*cmd:\s*(?P<command>.*conda)\s[create|install]") |
| 37 | with open(os.path.join(sys.prefix, 'conda-meta', 'history')) as f: |
| 38 | for line in f: |
| 39 | match = R.match(line) |
| 40 | if match: |
| 41 | return match.groupdict()['command'] |
| 42 | |
| 43 | # Fallback: assume conda is available on the system path. |
| 44 | return "conda" |
| 45 | |
| 46 | |
| 47 | CONDA_COMMANDS_REQUIRING_PREFIX = { |