asdf-community / asdf-python

Python plugin for the asdf version manager
https://github.com/asdf-vm/asdf
MIT License
643 stars 55 forks source link

"No preset version installed for command clear" after installing python 3.12.3 and anaconda3-2024.02-1 #187

Open cruzmanny opened 2 months ago

cruzmanny commented 2 months ago

Provide environment information

➜  ~ asdf info
OS:
Darwin MiMacBookAir.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103 arm64

SHELL:
zsh 5.9 (x86_64-apple-darwin23.0)

BASH VERSION:
3.2.57(1)-release

ASDF VERSION:
v0.14.0

ASDF INTERNAL VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions
ASDF_DATA_DIR=/Users/USERNAME/.asdf
ASDF_DIR=/opt/homebrew/opt/asdf/libexec
ASDF_CONFIG_FILE=/Users/USERNAME/.asdfrc

ASDF INSTALLED PLUGINS:
java                         https://github.com/halcyon/asdf-java.git master 8aef0e7
node                         https://github.com/asdf-vm/asdf-nodejs.git master c5b7c40
python                       https://github.com/asdf-community/asdf-python.git master 5e277e2

To Reproduce

asdf install python 3.12.3 asdf global python 3.12.3 asdf install python anaconda3-2024.02-1 asdf global python anaconda3-2024.02-1 asdf global python 3.12.3 Restart terminal or $SHELL enter "clear"

I found closed but related issues on this matter: https://github.com/asdf-vm/asdf/issues/414 https://github.com/asdf-community/asdf-python/issues/31

Describe the Bug

After installing python 3.12.3 and anaconda3-2024.02-1 then switching back and forth between versions; the "clear" command on terminal does not work. It does not clear my terminal screen but receive an error message.

➜ ~ clear No preset version installed for command clear Please install a version by running one of the following:

asdf install python 3.12.3

or add one of the following versions in your config file at /Users/USERNAME/.tool-versions python anaconda3-2024.02-1

➜ ~ cat .tool-versions node 20.12.2 python 3.12.3 java zulu-javafx-21.34.19

This error does not occur when I switch back to anaconda3-2024.02-1 from python 3.12.3 and enter "clear" when I have set python 3.12.3 globally. This also occurred on my Ubuntu machine. However, I "sudo apt reinstall ncurses-bin" and this fixed the issue for ubuntu.

Work around for macOS:

  1. add and alias: alias clear="/usr/bin/clear"
  2. Not recommended by Homebrew but after installing ncurses via homebrew: brew link --force ncurses echo 'export PATH="/opt/homebrew/opt/ncurses/bin:$PATH"' >> ~/.zshrc $SHELL

Expected Behaviour

After switching from anaconda to python 3.12.3 by using the asdf global command I should be able to clear my terminal screen without any issues. I am not sure why asdf shims or has a clear or why it supersedes the system's clear.

allemangD commented 2 months ago

It's worse than just clear, both anaconda and miniconda provide many executables that shadow system tools.

$ ls .asdf/installs/python/miniconda3-latest/bin
2to3          clear                idle          lz4cat            pcre2grep          sqlite3_analyzer                xmllint
2to3-3.12     compile_et           idle3         lzcat             pcre2_jit_test     tabs                            xmlwf
acountry      conda                idle3.12      lzcmp             pcre2posix_test    tclsh                           xz
activate      conda2solv           infocmp       lzdiff            pcre2test          tclsh8.6                        xzcat
adig          conda-content-trust  infotocap     lzegrep           pip                testsolv                        xzcmp
ahost         conda-env            installcheck  lzfgrep           pip3               tic                             xzdec
archspec      cph                  jsondiff      lzgrep            pkgdata            toe                             xzdiff
bsdcat        c_rehash             jsonpatch     lzless            pydoc              tput                            xzegrep
bsdcpio       curl-config          jsonpointer   lzma              pydoc3             tqdm                            xzfgrep
bsdtar        deactivate           k5srvutil     lzmadec           pydoc3.12          tset                            xzgrep
bunzip2       derb                 kadmin        lzmainfo          python             unlz4                           xzless
bzcat         distro               kdestroy      lzmore            python3            unlzma                          xzmore
bzcmp         dumpsolv             kinit         makeconv          python3.1          unxz                            zstd
bzdiff        genbrk               klist         mamba-package     python3.12         unzstd                          zstdcat
bzegrep       gencfu               kpasswd       mergesolv         python3.12-config  uuclient                        zstdgrep
bzfgrep       gencnval             krb5-config   ncursesw6-config  python3-config     wheel                           zstdless
bzgrep        gendict              ksu           nghttp            python-config      wish                            zstdmt
bzip2         genrb                kswitch       nghttpd           repo2solv          wish8.6                         
bzip2recover  gss-client           ktutil        nghttpx           reset              x86_64-conda_cos7-linux-gnu-ld  
bzless        icu-config           kvno          normalizer        sclient            x86_64-conda-linux-gnu-ld       
bzmore        icuexportdata        lz4           openssl           sim_client         xml2-config                     
captoinfo     icuinfo              lz4c          pcre2-config      sqlite3            xmlcatalog                      

All I really want out of all this is conda. Really, since conda requires shell integration, what I really need is to execute conda 'shell.zsh' 'hook' (for whichever $SHELL) one time and tweak the CONDA_EXE and CONDA_PYTHON_EXE environment variables in the shim. Problem is that the hook defines a function conda() that would shadow the shim itself.


Poking through the conda shell hooks it is not so simple; it looks like they might each use different environment variables.

They do define some unique environment variables, but they all seem to depend on CONDA_EXE and CONDA_PYTHON_EXE. I think those two are all an ideal plugin would manage.

$ conda shell.bash hook
$ conda shell.fish hook
$ conda shell.powershell hook
$ conda shell.tcsh hook
$ conda shell.xonsh hook
$ conda shell.zsh hook

I suppose only the shells which are also supported by asdf need to be handled here.