asdf-community / asdf-python

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

please adopt the anaconda shim blacklist #54

Open AlJohri opened 5 years ago

AlJohri commented 5 years ago

https://github.com/pyenv/pyenv/blob/master/pyenv.d/rehash/conda.d/default.list

instaling anaconda via asdf python kind of breaks the shell right now. I have to delete these shims manually as I run into issues

I'd be happy to help make this happen if you're amenable. thanks

danhper commented 5 years ago

Hi, thanks for reporting this. I personally do not use anaconda so I was not aware of this issue but I of course would like to see this fixed. At the moment, asdf does not have a way to blacklist shims, so we will need to support this in asdf to be able to fix this here. I think it is a reasonable addition, so let's discuss this in the asdf repository and see how we want to handle it.

danhper commented 5 years ago

Before we start discussing the issue in the main repo, I would like just a bit more context. Are the shims breaking anaconda installed by other python packages or by other languages? Could you please provide an example of shims which broke anaconda, and where they came from? Thanks a lot for your help.

AlJohri commented 5 years ago

@danhper they don't break anaconda, they break the rest of the system. for example, in that list of shims, you'll notice clear. When the shim exists, it returns something like:

Screen Shot 2019-05-12 at 7 38 02 PM

This is the same response for any of the shims in the last such as curl.

AlJohri commented 5 years ago

To replicate, run: asdf install python anaconda3-2018.12. I keep this installed side by side by regular python as a place to quickly test things without creating a virtualenv. To activate on the fly, this shell function works well:

function anaconda() {
    asdf shell python anaconda3-2018.12
}

Just rming the shims in that list fixes the issue.

AlJohri commented 5 years ago

And to answer your question to where they come from:

$ asdf which clear
/Users/johria/.asdf/installs/python/anaconda3-2018.12/bin/clear

It's a binary that anaconda packages. It works fine if anaconda is your global python. Otherwise the shim hits you with the above error.

danhper commented 5 years ago

@AlJohri Thanks a lot for the additional details.

In the meanwhile, I suggest you add anaconda as your other python version, it should already be better than having to delete the shims every now and then. For example.

asdf global python 3.7.2 anaconda3-2018.12

Something else I would like to know. I suppose anaconda expects you to be using the binaries it provides. How is this handled if those are not included in the shim? Does anaconda provide some kind of virtualenv which sets the correct path for you?

Thanks again for helping out.

AlJohri commented 5 years ago

@danhper I adopted your advice and things are a bit smoother.

I suppose anaconda expects you to be using the binaries it provides. How is this handled if those are not included in the shim? Does anaconda provide some kind of virtualenv which sets the correct path for you?

I think this is the logic that pyenv follows: https://github.com/pyenv/pyenv/blob/master/pyenv.d/rehash/conda.bash

https://github.com/pyenv/pyenv/blob/eb68ec9488f0df1f668e9272dd5bd8854edf1dff/pyenv.d/rehash/conda.bash#L16-L20

This code is referencing the default.list linked above.

michi-zuri commented 4 years ago

Anaconda recommends NOT to add it's bin folder to PATH by default. The bin folder itself will be added when running conda activate and removed again when running conda deactivate. By default only the folder condabin which only contains conda is added to the path.

What should happen when conda is installed but not active? I reckon only the shim conda should be created (not even python). conda activate not only shadows the PATH, but also runs some activation scripts of its packages and this is reversed by running conda deactivate.

gerrywastaken commented 4 years ago

It seems like this issue is caused by pyenv https://github.com/pyenv/pyenv/issues/843 https://github.com/pyenv/pyenv/issues/779

and apparently this plugin solves the issue: https://github.com/pyenv/pyenv-which-ext

davidbodow-st commented 3 years ago

This issue has been open for a while --- I completely understand the need for prioritization of other issues, but if there's no solution planned for it, it might at least be worthwhile to add a warning in the readme that installing anaconda will also introduce a laundry list of new shims that might break existing utilities.

Having something seemingly unrelated like curl just disappear because you installed anaconda but didn't activate it in asdf is very unintuitive in a version manager that is usually incredibly intuitive.

samcdavid commented 3 years ago

Ok, I was able to resolve this issue on my mac by first uninstalling the version on anaconda that I had installed.

Second, I then installed pyenv-which-ext with brew install pyenv-which-ext as suggested by @gerrywastaken

Finally, I was able to install the versions of anaconda that I needed and system programs like curl, clear, and which worked without issue.

The shims are still created, but they don't completely bork your system. @davidbodow-st this may resolve your issue.

samcdavid commented 2 years ago

Ok, here is another wrinkle to this situation as my system messed up again after my last post. Here is what I am doing now.

.tool-versions

python anaconda3-2021.11

.local_zshrc

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/<<username>>/.asdf/installs/python/anaconda3-2021.11/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/<<username>>/.asdf/installs/python/anaconda3-2021.11/etc/profile.d/conda.sh" ]; then
        . "/Users/<<username>>/.asdf/installs/python/anaconda3-2021.11/etc/profile.d/conda.sh"
    else
        export PATH="$PATH:/Users/<<username>>/.asdf/installs/python/anaconda3-2021.11/bin"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

So now what I do whenever I need to use conda, whenever I cd into a directory where I need conda I start with source .local_zshrc and then I can execute whatever conda commands that I need. If I open other shells and what not, everything works as expected. Another big change here is that when the path is exported, I put the conda bin at the end of my path rather than at the beginning. Everything is working as I need it to, but I haven't done extensive testing, so your mileage may vary. Good luck!

Side note: I also needed to do this when specifying conda as my second python version.

jtzero commented 2 years ago

@samcdavid seems optimal for https://direnv.net/ it will auto execute a file when you enter a directory (https://github.com/asdf-community/asdf-direnv)

gchallen commented 2 years ago

Just a +1 on this issue. It's very frustrating.

Note that this can also end up breaking asdf itself. Many asdf plugins seem to rely on curl, which is one of the shims that is broken by Anaconda. Running (for example) asdf list all mongodb shows a no available versions message, rather than the list of available plugins.

cristianriano commented 2 years ago

+1 for this issue. It makes working with Anaconda + ASDF combo very difficult.

There is a potential fix using the direnv plugins for asdf. But you have to create a .envrc in your HOME directory and get $ASDF_DIR/shims out of the PATH (steps in the README of the plugin) Don't think is the best solution but works. I think it should be supported natively by python asdf

allerasouza commented 2 years ago

+1 for this issue

tylerkahn commented 1 year ago

+1 breaking formambaforge as well

mazur-jeff commented 3 months ago

+1, I faced this issue after installing anaconda3-2024.02-1. I removed it using asdf uninstall python anaconda3-2024.02-1