Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid version syntax #154

Closed
Simon-chevolleau opened this issue Dec 21, 2023 · 24 comments · Fixed by #165
Closed

Invalid version syntax #154

Simon-chevolleau opened this issue Dec 21, 2023 · 24 comments · Fixed by #165
Assignees
Labels

Comments

@Simon-chevolleau
Copy link

Simon-chevolleau commented Dec 21, 2023

Expected behavior

conda-env-activate should activate a conda environment after, interactively, selecting it.

Experienced behavior

An error is returned, specifying the version 4.8.3 + a string: "can't". However, I don't fully understand from which application this version is related to.

Error

Debugger entered--Lisp error: (error "Invalid version syntax: ‘can't’ (must start with a...")
  signal(error ("Invalid version syntax: ‘can't’ (must start with a..."))
  error("Invalid version syntax: `%s' (must start with a nu..." "can't")
  version-to-list("can't")
  version<("4.8.3" "can't")
  conda--supports-json-activator()
  (if (conda--supports-json-activator) (let ((result (conda--call-json-subcommand "activate" env-dir))) (make-conda-env-params :path (s-join path-separator (alist-get 'PATH (alist-get 'path result))) :vars-export (alist-get 'export (alist-get 'vars result)) :vars-set (alist-get 'set (alist-get 'vars result)) :vars-unset (alist-get 'unset (alist-get 'vars result)) :scripts-activate (alist-get 'activate (alist-get 'scripts result)) :scripts-deactivate (alist-get 'deactivate (alist-get 'scripts result)))) (if (not (conda--supports-old-activate-format)) (error "Installed Conda version supports neither JSON nor ...") (make-conda-env-params :path (concat (conda--get-deprecated-path-prefix env-dir) path-separator (getenv "PATH")))))
  conda--get-activation-parameters("/home/simon/anaconda3/envs/python/")
  (let ((params (conda--get-activation-parameters env-dir)) (inhibit-message t)) (if (not (eq nil (progn (or (progn (and ... t)) (signal 'wrong-type-argument (list ... params))) (aref params 2)))) (conda--update-env-from-params params) (progn (setenv "VIRTUAL_ENV" env-dir) (setenv "CONDA_PREFIX" env-dir))) (setq exec-path (s-split (if (eq system-type 'windows-nt) ";" ":") (progn (or (progn (and (memq ... cl-struct-conda-env-params-tags) t)) (signal 'wrong-type-argument (list 'conda-env-params params))) (aref params 1)))) (message "new path? %s" (progn (or (progn (and (memq (type-of params) cl-struct-conda-env-params-tags) t)) (signal 'wrong-type-argument (list 'conda-env-params params))) (aref params 1))) (setenv "PATH" (progn (or (progn (and (memq (type-of params) cl-struct-conda-env-params-tags) t)) (signal 'wrong-type-argument (list 'conda-env-params params))) (aref params 1))))
  (let* ((env-dir (expand-file-name env-path)) (env-exec-dir (concat (file-name-as-directory env-dir) conda-env-executables-dir))) (pythonic-activate env-dir) (setq python-shell-virtualenv-root env-dir) (let ((params (conda--get-activation-parameters env-dir)) (inhibit-message t)) (if (not (eq nil (progn (or (progn ...) (signal ... ...)) (aref params 2)))) (conda--update-env-from-params params) (progn (setenv "VIRTUAL_ENV" env-dir) (setenv "CONDA_PREFIX" env-dir))) (setq exec-path (s-split (if (eq system-type 'windows-nt) ";" ":") (progn (or (progn (and ... t)) (signal 'wrong-type-argument (list ... params))) (aref params 1)))) (message "new path? %s" (progn (or (progn (and (memq ... cl-struct-conda-env-params-tags) t)) (signal 'wrong-type-argument (list 'conda-env-params params))) (aref params 1))) (setenv "PATH" (progn (or (progn (and (memq ... cl-struct-conda-env-params-tags) t)) (signal 'wrong-type-argument (list 'conda-env-params params))) (aref params 1)))) (setq eshell-path-env (getenv "PATH")) (conda--set-env-gud-pdb-command-name) (run-hooks 'conda-postactivate-hook))
  (if (not (conda--env-dir-is-valid env-path)) (error "Invalid conda environment path specified: %s" env-path) (conda-env-deactivate) (setq conda-env-current-path env-path) (setq conda-env-current-name (conda-env-dir-to-name env-path)) (set (make-local-variable 'conda-project-env-path) env-path) (run-hooks 'conda-preactivate-hook) (add-to-list 'conda-env-history conda-env-current-name) (let* ((env-dir (expand-file-name env-path)) (env-exec-dir (concat (file-name-as-directory env-dir) conda-env-executables-dir))) (pythonic-activate env-dir) (setq python-shell-virtualenv-root env-dir) (let ((params (conda--get-activation-parameters env-dir)) (inhibit-message t)) (if (not (eq nil (progn (or ... ...) (aref params 2)))) (conda--update-env-from-params params) (progn (setenv "VIRTUAL_ENV" env-dir) (setenv "CONDA_PREFIX" env-dir))) (setq exec-path (s-split (if (eq system-type 'windows-nt) ";" ":") (progn (or (progn ...) (signal ... ...)) (aref params 1)))) (message "new path? %s" (progn (or (progn (and ... t)) (signal 'wrong-type-argument (list ... params))) (aref params 1))) (setenv "PATH" (progn (or (progn (and ... t)) (signal 'wrong-type-argument (list ... params))) (aref params 1)))) (setq eshell-path-env (getenv "PATH")) (conda--set-env-gud-pdb-command-name) (run-hooks 'conda-postactivate-hook)))
  (let ((env-path (or path (read-directory-name "Conda environment directory: ")))) (if (not (conda--env-dir-is-valid env-path)) (error "Invalid conda environment path specified: %s" env-path) (conda-env-deactivate) (setq conda-env-current-path env-path) (setq conda-env-current-name (conda-env-dir-to-name env-path)) (set (make-local-variable 'conda-project-env-path) env-path) (run-hooks 'conda-preactivate-hook) (add-to-list 'conda-env-history conda-env-current-name) (let* ((env-dir (expand-file-name env-path)) (env-exec-dir (concat (file-name-as-directory env-dir) conda-env-executables-dir))) (pythonic-activate env-dir) (setq python-shell-virtualenv-root env-dir) (let ((params (conda--get-activation-parameters env-dir)) (inhibit-message t)) (if (not (eq nil (progn ... ...))) (conda--update-env-from-params params) (progn (setenv "VIRTUAL_ENV" env-dir) (setenv "CONDA_PREFIX" env-dir))) (setq exec-path (s-split (if (eq system-type ...) ";" ":") (progn (or ... ...) (aref params 1)))) (message "new path? %s" (progn (or (progn ...) (signal ... ...)) (aref params 1))) (setenv "PATH" (progn (or (progn ...) (signal ... ...)) (aref params 1)))) (setq eshell-path-env (getenv "PATH")) (conda--set-env-gud-pdb-command-name) (run-hooks 'conda-postactivate-hook))) (if (or conda-message-on-environment-switch (called-interactively-p 'interactive)) (message "Switched to conda environment: %s" env-path)))
  conda-env-activate-path("/home/simon/anaconda3/envs/python/")
  (let* ((env-name (or name (conda--read-env-name))) (env-dir (conda-env-name-to-dir env-name))) (conda-env-activate-path env-dir))
  conda-env-activate()
  funcall-interactively(conda-env-activate)
  call-interactively(conda-env-activate record nil)
  command-execute(conda-env-activate record)
  execute-extended-command(nil "conda-env-activate" #("conda ac" 0 8 (ws-butler-chg chg)))
  funcall-interactively(execute-extended-command nil "conda-env-activate" #("conda ac" 0 8 (ws-butler-chg chg)))
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

Config

(use-package! conda
  :custom
  (conda-anaconda-home "/home/simon/anaconda3")
  :init
  (conda-env-initialize-interactive-shells)
  (conda-env-initialize-eshell)
  (conda-env-autoactivate-mode t)
  )

Environment

OS: Ubuntu 24.04
Emacs: 29.1
Doom core: v3.0.0-pre HEAD -> master 03d692f1 2023-12-08 15:11:45 -0500
Doom modules: v23.12.0-pre HEAD -> master 03d692f1 2023-12-08 15:11:45 -0500
conda: 23.7.4
conda.el (MELPA): 20231109.219

@necaris
Copy link
Owner

necaris commented Dec 22, 2023

It looks like an issue with conda itself -- can you show the output of conda -V in your terminal?

@Simon-chevolleau
Copy link
Author

Here is my versions:

  • conda version : 23.7.4
  • conda-build version : 3.28.2
  • python version : 3.11.5.final.0

@WhoisDonlee
Copy link

I have a similar error. I think it's unrelated to conda.el.

version<("4.8.3" "can't") checks if your conda version is higher than 4.8.3 by running conda -V in a new shell. conda.el grabs the second value, which should be the conda version. Instead, opening a new shell yields an error and "can't" is the second value.

Opening vterm probably shows the error that's causing the issue.

@WhoisDonlee
Copy link

conda/conda#13451
microsoft/vscode-python#22752

For me it was an issue with the conda python plugin, which unsets the CONDA_PREFIX variable.
Setting the CONDA_PREFIX env var fixed it for me.

@necaris
Copy link
Owner

necaris commented Jan 16, 2024 via email

@Simon-chevolleau
Copy link
Author

Simon-chevolleau commented Oct 2, 2024

Hello, sorry for not responding since my last comment. I have been able to use conda.el, I don't know how and why the error disappeared. But it came back today.
I'm settings CONDA_PREFIX since the beginning and it does nothing else. I did a fresh installation today of mamba.

I installed mamba at /home/simon/mamba.
and set the following configuration inside my config.el (Doom emacs):

(setenv "CONDA_PREFIX" "/home/simon/mamba")

(use-package! conda
  :custom
  (conda-anaconda-home "/home/simon/mamba")
  :init
  (conda-env-autoactivate-mode)
  (conda-env-initialize-interactive-shells)
  (conda-env-initialize-eshell)
  (setq-default mode-line-format (cons mode-line-format '(:exec conda-env-current-name)))

  ;; if you want to automatically activate a conda environment on the opening of a file:
  (add-hook 'find-file-hook (lambda () (when (bound-and-true-p conda-project-env-path)
                                            (conda-env-activate-for-buffer))))
  )

conda -V returns: conda 24.7.1
So way higher than 4.8.3, I don't know where 4.8.3 come from.

which conda return: /home/simon/mamba/bin/conda

I have no idea why there is this error, I ll give a try with anaconda instead of mamba.

Edit: In my first comment, I was using anaconda and I'm now on mamba.

@necaris
Copy link
Owner

necaris commented Oct 2, 2024

Thank you for the update! I'll have a look at this -- there are patches in place in Doom and other projects for Mamba support, I'll have to look at that.

@Simon-chevolleau
Copy link
Author

There is definitely something wrong, I tried with Anaconda instead and I got the same error. Now I try back with mamba, then it works, even with wrong CONDA_PREFIX variable and config:

(setenv "CONDA_PREFIX" "/home/simon/anaconda3")

(use-package! conda
  :custom
  (conda-anaconda-home "/home/simon/anaconda3")
  :init
  (conda-env-autoactivate-mode)
  (conda-env-initialize-interactive-shells)
  (conda-env-initialize-eshell)
  (setq-default mode-line-format (cons mode-line-format '(:exec conda-env-current-name)))

  ;; if you want to automatically activate a conda environment on the opening of a file:
  (add-hook 'find-file-hook (lambda () (when (bound-and-true-p conda-project-env-path)
                                            (conda-env-activate-for-buffer))))
  )

where my path is /home/simon/miniforge3 ...
There is probably something I don't fully understand + the probability that I misunderstand the power of Doom sync about env variable initialisation.
Now that the problem disappeared, should we close this issue or let it pending ?

@necaris
Copy link
Owner

necaris commented Oct 2, 2024

Let's leave it open, since there's clearly something wrong I should look into.

@necaris necaris self-assigned this Oct 2, 2024
@Simon-chevolleau
Copy link
Author

I've know idea why, but the error returned, so if you want me to check some stuffs, let me know.

@WhoisDonlee
Copy link

The shell points to the new installation (24.7.1). But it looks like there is still a reference to the old installation (probably in ~/.emacs/.local/env).
Does /home/simon/anaconda3/bin/conda -V return 4.8.3?

@Simon-chevolleau
Copy link
Author

Simon-chevolleau commented Oct 3, 2024

I removed anaconda3 for mamba and I manually activate my envs with the pyvenv package as a workaround.
/home/simon/miniforge3/bin/conda -V returns 'conda 24.7.1'
I also test this one /home/simon/miniforge3/condabin/conda -V and it returns the same : 'conda 24.7.1'.

@WhoisDonlee
Copy link

What about (conda--get-installed-version).
Looks like that does not return a value above 4.8.3

(version< "4.8.3" (conda--get-installed-version)))

Did you install conda in init.el (python +conda) or in packages.el? Doom applies some doom specific config IIRC

@Simon-chevolleau
Copy link
Author

I installed conda through packages.el. I removed it and use default installation as you mentionned, but it doesn't solve the problem.

How can I call the internal function conda--get-installed-version on my own ?

@WhoisDonlee
Copy link

With M-x eval-expression, and then enter (conda--get-installed-version) with brackets

@Simon-chevolleau
Copy link
Author

It returns "cannot". I will try to investigate this eval-expression.

@necaris
Copy link
Owner

necaris commented Oct 5, 2024

@Simon-chevolleau Any chance you could try the branch in #165 and see if that fixes it?

@necaris necaris added the bug label Oct 5, 2024
@Simon-chevolleau
Copy link
Author

I'm still getting the same error with "fix/invalid-version-string" branch, with "cannot" returned.
Can I do anything on my side to help you investigate this bug ?

@necaris
Copy link
Owner

necaris commented Oct 5, 2024

@Simon-chevolleau Can you paste the full output from running conda -V in your terminal?

After I uninstalled and reinstalled, to make sure I didn't have any lingering issues from a really old Conda installation, this is what I get:

$ conda -V                                                                                                                            
conda 24.9.1

@necaris necaris reopened this Oct 5, 2024
@Simon-chevolleau
Copy link
Author

Here it is:

simon@xxx:~$ conda -V
conda 24.7.1

@WhoisDonlee
Copy link

This should display the whole error message: (shell-command-to-string (format "\"%s\" -V" (conda--get-executable-path)))

Does (conda--get-executable-path) point to the right binary?
You could try to regenerate doom's envvars. To me it looks like emacs doesn't point to the right location since conda -V returns different things within emacs and within the shell

@Simon-chevolleau
Copy link
Author

(shell-command-to-string (format "\"%s\" -V" (conda--get-executable-path))) returns :

"bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
conda 24.7.1
"

While (conda--get-executable-path) returns /home/simon/miniforge3/bin/conda

I guess I solved the problem thank to you recommandations:
I removed this line in my config file:
(setq shell-command-switch "-ic") to (setq shell-command-switch "-c")
Then, regenerate doom envvars + doom sync. And it works !
Thank you a lot !

@necaris
Copy link
Owner

necaris commented Oct 7, 2024

Thank you @WhoisDonlee for helping !

@necaris necaris closed this as completed Oct 7, 2024
@Simon-chevolleau
Copy link
Author

I get back to this problem, and I know how to exactly trigger it, it is not related to doom envvars.
In fact, setting specifying emacs to use interactive shell using: (setq shell-command-switch "-ic") was the problem. I was using this to get bash aliases in emacs. When using only (setq shell-command-switch "-ic"), it will work perfectly as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants