3

I've been using Python command 'conda' in the terminal on my Mac. But when I run a command like 'conda activate ...' in Emacs's shell (M-x shell), it gives me this objection:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

It tells me

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

But when I run conda init bash, it has no effect: I just get back the same result trying to run the 'conda activate ...' command again. Is there anything I can do about this?

Note: I just want to run conda in the shell as I do in the terminal. I'm not really interested in other improved methods of running conda in Emacs (such as conda mode). Thank you.

9
  • What does C-h v explicit-shell-file-name produce?. does it show path to your regular bash shell. If not give its path explicitly by using Emacs' customization interface. Commented Oct 14, 2020 at 17:14
  • Please clarify what you mean by "trying run conda again". E.g. say precisely what you do and where between the two.
    – Stefan
    Commented Oct 14, 2020 at 21:12
  • @minibuffer: it showed the value was nil, so I changed to my bash path (/bin/bash). However, when I retried my commands above, there was no change. Commented Oct 15, 2020 at 22:07
  • @Stefan: when I wrote 'trying run conda again' I should have written "trying TO run conda again", and I meant that I tried to again run a command like 'conda activate ...' in Emacs's shell, i.e., after I'd done the 'conda init bash' command. Commented Oct 15, 2020 at 22:09
  • 1
    Have you tried running conda init $SHELL in your regular $SHELL outside of Emacs?. Also, consider using eshell. Commented Oct 16, 2020 at 17:35

3 Answers 3

1

I think you need to use the emacs package conda.el

The problem is that conda activate will change the $PATH of the shell that it is in. This will not be reflected in emacs.

It allows you to see and change conda virtual environments in emacs.

This includes support for eshell

Support for eshell is turned on by calling conda-env-initialize-eshell. After doing this, any new eshells you launch will be in the correct environment and have access to installed executables, etc. The mode also provides a variety of virtualenvwrapper-like commands that work identically to their bash/zsh counterparts (described in detail below). Note that in contrast to how interactive shells work, Eshell shares an environment with Emacs, so if you activate or deactivate in one, the other is affected as well. Note that this requires the variable eshell-modify-global-environment to be set to true -- running conda-env-initialize-eshell causes this to occur.

-1

To not get into an extended discussion in comments I am moving this to an answer.

If your commands work in your regular $SHELL but not in emacs, the following will probably help.

https://github.com/purcell/exec-path-from-shell

I highly recommend you use the excellent exec-path-from-shell package if you are not using it already. IMHO, this is one of those "must-have"s if you are using Emacs on Mac OS.

-1

conda is an executable which is added to the environment variable PATH. Your error notes that the command, the executable, can't be found. You need to make it discoverable. There are numerous ways this could be done. Fortunately, the conda distribution provides many scripts to set up shell environments. You can likely leverage those.

On Windows, it was sufficient for me to call conda.bat. This is located within ../Anaconda3/condabin/. Looking in ../Anaconda3/Scripts/, I see activate which is a shell script for Unix-like environments (i.e. Mac OS). It calls ../Anaconda3/etc/profile.d/conda.sh. This looks analogous to conda.bat.

On Windows, this works for me:

  1. M-x shell
  2. Call C:\path\to\Anaconda3\conda.bat activate <my-env> within shell

You might have luck with:

  1. M-x shell
  2. Call /path/to/Anaconda3/etc/profile.d/conda.sh activate <my-env>

Of course, check conda.sh for the precise way arguments are handled.

2
  • I don't think this is simple PATH problem with finding the conda executable. The error message is not the general "bash: conda: command not found" error. Rather, "CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.". Notice that the error message recommends a conda-specific remedy. Therefore, I conclude this error message is coming from conda, not from the shell. Besides all that, I did try replacing the command 'conda' with '<full path>/conda', and it gave the exact same error message. Thanks anyhow for suggestions. Commented Nov 6, 2020 at 20:04
  • Mmk, I misread your question. Maybe this will help: github.com/conda/conda-build/issues/3371 Commented Nov 6, 2020 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.