necaris / conda.el

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

Incorrect Windows path to conda.exe after #57 #59

Closed notuntoward closed 4 years ago

notuntoward commented 4 years ago

On my Windows machine, Anaconda has installed conda.exe in:

c:/Users/scott/anaconda3/Scripts/conda.exe

but since #57, the conda package looks for it in:

c:/Users/scott/anaconda3/bin/conda

Or so it seems, if I look at the error message emacs gives me when I try to activate an environment named "stdso":

Error (use-package): conda/:config: Error: executing command "c:/Users/scott/anaconda3/bin/conda ..activate "cmd.exe" c:/Users/scott/anaconda3/envs/stdso" produced error code 1

Before #57, I think that the conda package looked in my PATH environment variable for a conda.exe, which worked correctly.

I have set both conda-env-home-directory and conda-anaconda-home to:

c:/Users/scott/anaconda3

Shiandow commented 4 years ago

I think this is because of some recent changes to conda--get-path-prefix. In particular it was made to default to the 'bin' folder even on windows.

On my end I've managed to fix it by overriding the function to use the conda-env-executables-dir which does list the correct path, and to use quoted paths (just in case there is a space in there somwhere). You can try it out by adding the following to your .emacs somewhere:

(with-eval-after-load 'conda
    (defun conda--get-path-prefix (env-dir)
    "Get a platform-specific path string to utilize the conda env in ENV-DIR.
It's platform specific in that it uses the platform's native path separator."
    (s-trim
     (with-output-to-string
       (with-current-buffer standard-output
         (let* ((conda-executable-path
                 (concat (file-name-as-directory conda-anaconda-home) (file-name-as-directory conda-env-executables-dir) "conda"))
                (command "\"%s\" ..activate \"%s\" \"%s\"")
                (formatted-command (format command
                                           conda-executable-path
                                           (if (eq system-type 'windows-nt)
                                               "cmd.exe"
                                             "bash")
                                           env-dir))
                (return-code (process-file shell-file-name nil '(t nil) nil shell-command-switch formatted-command)))
           (unless (= 0 return-code)
             (error (format "Error: executing command \"%s\" produced error code %d" formatted-command return-code)))))))))

I've made a pull request #60 with these changes.

notuntoward commented 4 years ago

Thanks! I'll give it a try as soon as it ends up on melpa.

notuntoward commented 4 years ago

@necaris and @Shiandow: This is to confirm that @Shiandow's fix works for me. Anything else needed to get #60 into melpa?

necaris commented 4 years ago

Closed by #60

necaris commented 4 years ago

@notuntoward can you confirm if the latest version on Melpa (which I've confirmed matches the most recent commit to master) works for you? This should include #60

notuntoward commented 4 years ago

Yes, it works for me. Thanks.