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

How to update vf after brew update #189

Closed
kameshsampath opened this issue Aug 12, 2020 · 13 comments
Closed

How to update vf after brew update #189

kameshsampath opened this issue Aug 12, 2020 · 13 comments
Labels

Comments

@kameshsampath
Copy link

I tried doing a brew update and brew upgrade, which updated my python from 3.7 to 3.8. Sadly I see I was not able to uninstall and reinstall vf becuase of the following issue

fish: Unknown command: /usr/local/opt/python/bin/python3.7
/usr/local/lib/python3.7/site-packages/virtualfish/virtual.fish (line 542):
    $python -m virtualfish.loader.installer uninstall
    ^
in function '__vf_uninstall'
        called on line 1 of file /usr/local/lib/python3.7/site-packages/virtualfish/virtual.fish
in function 'vf' with arguments 'uninstall'
VirtualFish has been uninstalled from this shell.
Run 'exec fish' to reload Fish.
Note that the Python package will still be installed and needs to be removed separately (e.g. using 'pip uninstall virtualfish').

Sorry of about my ignorance, after some debug and analysis I see that ~/.confg/fish/conf.d/virtuafish-loader.fish was still pointing to older python in my case 3.7.

How to overcome these issues ?? Is there a way to update vf in cleaner way ?

@justinmayer
Copy link
Owner

justinmayer commented Aug 12, 2020

Hi Kamesh. I feel your pain. I’m going to provide two answers to this question: one short, and one long.

Short Version:

This is Homebrew’s fault. Homebrew maintainers know that their upgrade behavior causes these problems. They don’t care. The easiest workaround is probably something like the following:

mv ~/.config/fish/conf.d/virtualfish-loader.fish ~/Desktop/virtualfish-loader.fish-old
exec fish
python -m pip install virtualfish
vf install  # or: "vf install projects environment update_python […]" to enable desired plugins, if any
exec fish

I think that will help resolve the clusterf*ck that Homebrew created.

Long Version:

As of a few months ago, Homebrew maintainers changed the default upgrade behavior to delete all old versions of every package. That includes Python, which means every time they release a new version, there is the very real potential that any (non-Homebrew) software that depends on the previous Python version (no matter how minor)… will just break horribly and without any warning.

Up until recently, this happened to me constantly. I would activate a virtual environment and immediately discover that it had been smashed to bits by a Homebrew upgrade. Then another, and another. All these virtual environments… broken. And now I have to re-create them all over again. Why??

Because Homebrew’s Python isn’t for you — it’s for them. The sole purpose of Homebrew’s Python formula, it seems, is only to enable other Homebrew software — that relies on a Python interpreter — to work. And that would all be totally fine, IF that warning was plastered in big red letters all over the place. That way it would be impossible to miss, and then nobody except hardcore masochists would ever try to use Homebrew Python for any productive purpose whatsoever.

Ergo, I don’t use Homebrew Python for anything. At all. In fact, I would love to not even have Homebrew’s Python installed on my systems, and I even tried that briefly before realizing the futility: so many other formula rely upon the Python formula that there’s nearly a 100% chance that the Python formula will get automatically installed within five minutes of using Homebrew.

Which is fine. Just because it’s installed on my systems doesn’t mean I have to use it for anything, which I don’t. So what do I use instead?

I use asdf:

brew install asdf
source (brew --prefix)/opt/asdf/asdf.fish
echo source (brew --prefix)/opt/asdf/asdf.fish >> ~/.config/fish/config.fish
asdf plugin add python
asdf install python 3.8.5
asdf global python 3.8.5
python -m pip install -U pip setuptools virtualenv virtualfish
asdf reshim python

Then, in my config.fish, I anoint a Python version as my preferred, go-to version when creating new virtual environments:

set -g VIRTUALFISH_DEFAULT_PYTHON "$HOME/.asdf/installs/python/3.8.5/bin/python"

After switching to this solution, would you like to guess how many times I’ve had something break due to a Python upgrade? Right. Zero. Zero times. Because now I am in control of when older Python versions are swept away, I can run vf update_python 3.8.5 on an older active environment and then, once I’ve confirmed no other virtual environments rely on version 3.8.4, I can then uninstall that version without worrying about something breaking.

Plus, I added built-in support for asdf to VirtualFish, so you can specify any arbitrary installed version when creating a virtual environment:

asdf install python 3.7.8
vf new -p 3.7.8 my-new-environment

Let me know if you have any questions about this. I imagine you weren’t expecting a seething rant-fest when you submitted this issue, but I needed to vent. Thanks for giving me an opportunity for some catharsis. 😁

@kameshsampath
Copy link
Author

@justinmayer super thanks for this write up, I should shift to asdf for portability and save some cycles for me. But one thing not clear to me how to install virtualfish once I have installed python via asdf and then added the asdf/bin to my path. I use a regular pip install virtualfish which ideally installs virutalfish to my asdf python site-packages. But I dont find the vf and vf update_python commands :( . Think I am missing something.

@justinmayer
Copy link
Owner

justinmayer commented Aug 13, 2020

Create a new terminal session. What output do you get when you run the following commands?

  1. echo $PATH
  2. which python
  3. which pip
  4. asdf current python

@kameshsampath
Copy link
Author

kameshsampath commented Aug 13, 2020 via email

@kameshsampath
Copy link
Author

kameshsampath commented Aug 13, 2020 via email

@justinmayer
Copy link
Owner

What happens if you run asdf reshim and then vf --help? Does reshimming fix the problem?

@kameshsampath
Copy link
Author

Hi Justin,

I need to wait to try this, my mac crashed and need to wait for it to be fixed. Once I get it back will try this and let you know. If you wish you can close this issue :).

Thank you so much for your detailed explanation :)

@kameshsampath
Copy link
Author

just one question - so with asdf python I still need to follow the same method to install virtualfish right?

@justinmayer
Copy link
Owner

Earlier today I made some edits to the steps above, adding the following:

[…]
python -m pip install -U pip setuptools virtualenv virtualfish
asdf reshim python

Once your Mac is up-and-running again, by all means please let me know how it goes! 😊

@justinmayer
Copy link
Owner

I tested the above instructions on a fresh Ubuntu 20.04 Focal VPS, and everything worked as expected. If that isn't the case for you, please post a comment here so I can re-open it. Cheers!

@kameshsampath
Copy link
Author

thanks @justinmayer let me try on my linux as well

@kameshsampath
Copy link
Author

@justinmayer thanks for all inputs, it works well now. I tried doing it even windows with WSL2 Debian 10.

@pixelknitter
Copy link

pixelknitter commented Feb 11, 2021

The combination of the short and long answer did the trick for me. Thanks for your clarity of the problem!

Also, I relate to the fact that I've had Python hijacked far too many times, thanks for this solution.

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

No branches or pull requests

3 participants