necaris / conda.el

Emacs helper library (and minor mode) to work with conda environments
MIT License
153 stars 49 forks source link

Interactive-Shell Issue: <env_name>: command not found #87

Closed hnisonoff closed 2 years ago

hnisonoff commented 3 years ago

I am having trouble getting conda.el to work well with my interactive shell (M-x shell). When I run M-x conda-env-activate <env_name> and then run M-x shell I get: <env_name>: command not found

Presumably conda.el is missing the conda activate part when initializing the shell, but I'm not sure why?

Here is my setup, which is slightly non-standard because my conda home director is in /anaconda3/ instead of ~anaconda3/.

(use-package conda
  :ensure t
  :init
  (progn
    (require 'conda)
    (custom-set-variables
     '(conda-anaconda-home "/anaconda3/"))
    (setq conda-env-home-directory (expand-file-name "/anaconda3/"))
    (conda-env-initialize-interactive-shells)
    (conda-env-initialize-eshell)
    (conda-env-autoactivate-mode t)
))

Thanks!

louisdecharson commented 3 years ago

Having the same here ! Any news @hnisonoff ?

louisdecharson commented 2 years ago

I've tried to debug it and for some reason activate-command is not set after

(activate-command (if (eq system-type 'windows-nt
                                   '("activate")
                                   '("conda" "activate"))))

e.g.:

(message "activate command: %s" activate-command)

yields: activate-command: nil

I've ended up modifying the function conda-env-shell-init in conda.el as:

;;;###autoload
(defun conda-env-shell-init (process)
  "Activate the current env in a newly opened shell PROCESS."
  ;; TODO: maintain compatibility with an older Conda version. Do we
  ;; check the Conda version and cache it?
  ;; TODO: make sure the shell has been set up for `conda activate`!
  ;; Do we need to `eval' the conda activation script every time?
  (let* ((activate-command (if (eq system-type 'windows-nt
                                   '("activate")
                                   '("conda" "activate"))))
         (activate-command (if (not activate-command) '("conda" "activate") activate-command))
         (full-command (append activate-command `(,conda-env-current-name "\n")))
         (command-string (combine-and-quote-strings full-command)))
    (comint-send-string process command-string)
    ))
necaris commented 2 years ago

Could you submit that as a PR, perhaps?

Louis de Charsonville @.***> writes:

I've tried to debug it and for some reason activate-command is not set after

(activate-command (if (eq system-type 'windows-nt '("activate") '("conda" "activate"))))

e.g.:

(message "activate command: %s" activate-command)

yields: activate-command: nil

I've ended up modifying the function conda-env-shell-init in conda.el as:

;;;###autoload (defun conda-env-shell-init (process) "Activate the current env in a newly opened shell PROCESS." ;; TODO: maintain compatibility with an older Conda version. Do we ;; check the Conda version and cache it? ;; TODO: make sure the shell has been set up for conda activate! ;; Do we need to eval' the conda activation script every time? (let* ((activate-command (if (eq system-type 'windows-nt '("activate") '("conda" "activate")))) (activate-command (if (not activate-command) '("conda" "activate") activate-command)) (full-command (append activate-command(,conda-env-current-name "\n"))) (command-string (combine-and-quote-strings full-command))) (comint-send-string process command-string) ))

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

-- Rami Chowdhury A mind all logic is like a knife all blade - it makes the hand bleed that uses it. -- Rabindranath Tagore

louisdecharson commented 2 years ago

Hi @necaris, To me your code should work just fine, ie:

((activate-command (if (eq system-type 'windows-nt
                                   '("activate")
                                   '("conda" "activate"))))

I don't understand why it does not. So I am happy to submit a PR but I feel my solution is more a plaster than anything else and a more appealing solution would fix the let activate-command part.

UPDATE: understood the issue in above code and submitted a PR to fix it

louisdecharson commented 2 years ago

Ok got the issue, it's was a simple parenthesis problem, I've submitted a PR to fix it: https://github.com/necaris/conda.el/pull/95

necaris commented 2 years ago

Closing as fixed by #95