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.

  • 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. – Cousin Dupree Oct 14 '20 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 Oct 14 '20 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. – user3705389 Oct 15 '20 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. – user3705389 Oct 15 '20 at 22:09
  • @Stefan: OK, I edited to address your comment. – user3705389 Oct 16 '20 at 17:10
  • 1
    Have you tried running `conda init $SHELL` in your regular `$SHELL` outside of Emacs?. Also, consider using `eshell`. – Cousin Dupree Oct 16 '20 at 17:35
  • @minibuffer: I tried ```conda init bash``` outside Emacs ($SHELL is /bin/bash), and it had no apparent effect in Emacs shell. Also, I tried ```eshell```, but it doesn't do any better. – user3705389 Oct 20 '20 at 15:43
  • It would seem an init scriot like .bashrc or .bash_profile isn't getting run in your Emacs shells. Does anything in [this thread](https://github.com/conda/conda/issues/7980) help – gregoryg Oct 21 '20 at 13:57
  • @user3705389, were you able to resolve this? I upgraded my MacOS and am facing this issue. Everything worked prior to the upgrade. – MadPhysicist Apr 30 '21 at 11:59

3 Answers3

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.

mmmmmm
  • 491
  • 1
  • 4
  • 19
-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.

Cousin Dupree
  • 358
  • 3
  • 12
-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.

Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
  • 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 '/conda', and it gave the exact same error message. Thanks anyhow for suggestions. – user3705389 Nov 06 '20 at 20:04
  • Mmk, I misread your question. Maybe this will help: https://github.com/conda/conda-build/issues/3371 – Lorem Ipsum Nov 06 '20 at 21:12