justinmayer / virtualfish

Fish shell tool for managing Python virtual environments
MIT License
1.06k stars 100 forks source link

update_python plugin: Erroneous error when updating a virtualenv which has nothing installed #184

Closed adamtheturtle closed 4 years ago

adamtheturtle commented 4 years ago

Issue

I created a virtualenv using VirtualFish.

I did not install anything with pip.

Later, I enabled the update_python plugin.

I ran update_python.

I see ERROR: You must give at least one requirement to install (see "pip help install").

I expect that there would be no such error.

justinmayer commented 4 years ago

I would expect that error given the circumstances. What exactly were you trying to achieve?

The purpose of the update_python plugin, as I understand it anyway, is to migrate an existing virtual environment to a newer version of Python. It does that by running pip freeze, creating a new virtual environment, and then Pip-installing the frozen requirements into the new virtual environment. If you don't have any packages installed in your virtual environment, then there is nothing to migrate.

adamtheturtle commented 4 years ago

Thank you for the quick response.

I wanted to pip install --upgrade pip in all of my virtualenvs.

Some of those virtualenvs showed:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/adam/.virtualenvs/auto_ex/bin/python3.8
  Reason: image not found

(or very similar).

I then thought to use update_python essentially to remove that error from each virtualenv.

I then ran update_python on each virtualenv and got this error.

What is confusing is that it ends with an error, but appears that everything has worked: I now have a virtualenv with an updated Python and the same requirements installed (i.e. no requirements).

If the command were called migrate_requirements_to_new_python or similar I wouldn't have opened this.

justinmayer commented 4 years ago

I didn't write this plugin, but I think the existing docs are fairly clear on this topic. If the Python binary is no longer present (e.g., which happens after brew upgrade python), then update_python may not be what you want. The fix_python command, on the other hand, might be more appropriate. But even that may not behave as you expect if the Python executable is gone.

For further discussion, see: #141. If you'd like to chip in and help implement a better solution for this condition, your assistance would be most helpful.

justinmayer commented 4 years ago

I added a check that will skip the pip install $packages step if the virtual environment has no$packages installed.

adamtheturtle commented 4 years ago

Thank you @justinmayer ! I'm sorry I didn't chip in.