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

When creating a virtual environment, upgrade pip in webui.bat/webui.sh #15750

Merged
merged 1 commit into from
Jun 8, 2024

Conversation

MarcusNyne
Copy link
Contributor

The default version of PIP with Python 3.10 does not record installation metadata properly for requirements installed using an url (egg-style), resulting in invalid lines when PIP FREEZE is called. For example, the packages clip and cstr are problematic. This makes it difficult to recreate a stable diffusion virtual environment. Upgrading PIP during virtual environment creation remedies this problem. I have found this is corrected in v24 of PIP.

Pip will be upgraded upon immediately creating the virtual environment. If the pip upgrade fails, this should not cause the script to fail (treat as a warning). Once the environment is created, it will not attempt further updates to pip on subsequent executions.

Description

  • Upgrade PIP during virtual environment creation so that PIP FREEZE will report accurate information
  • Added PIP --upgrade command to webui.bat and webui.sh
  • To reproduce this issue, review installation of clip and cstr, which report incorrect information in PIP FREEZE
  • Continues execution when pip upgrade fails (treated as a warning)
  • Pip is not upgraded when the virtual environment is already present
  • Should only ever upgrade the virtual environment (not the system environment)

Screenshots/videos:

Checklist:

Note: tested on Windows and Darwin Linux (Mac)

Pip will be upgraded upon immediately creating the virtual environment.  If the pip upgrade fails, this should not cause the script to fail (treat as a warning).  After the environment is created, it will not attempt further updates to pip.
@light-and-ray
Copy link
Contributor

As I see you're updating pip before venv activate, so - globally. It's a bad as I see. Not only changing pip version globally is bad, also some systems have protected the global environment, like mine (requires big additional command line flag), and it will break the script

@light-and-ray
Copy link
Contributor

You are making an extension - you can add this upgrade in it's install.py file or left in installation instruction

@MarcusNyne
Copy link
Contributor Author

As I see you're updating pip before venv activate, so - globally. It's a bad as I see. Not only changing pip version globally is bad, also some systems have protected the global environment, like mine (requires big additional command line flag), and it will break the script

@light-and-ray , thank you for taking the time to review the code. I greatly appreciate it. It is true that the code happens before the activate section. I did this purposefully. The python executable that the pip command is executing under is the executable file located in the virtual environment Scripts folder. When you run python this way, the context is the virtual environment. This is guaranteed never to run pip globally, because the global python will not be in this folder. I thought this was the safest way to make sure the upgrade does not happen globally.
"%VENV_DIR%\Scripts\Python.exe" -m pip install --upgrade pip

Thank you for noticing that I am developing stable diffusion extensions. The Automatic1111 extensions work very well. I still need to do some work on the ComfyUI custom nodes, then I will release them together. Personally, I prefer Automatic1111, and my extensions work better in that environment, but I thought it would be best to release them together.

I like your kitten icon.

@light-and-ray
Copy link
Contributor

light-and-ray commented May 10, 2024

Maybe I misunderstood you. What do you mean python's executable is located locally? It only exists on windows and only in the portable binary release. If you install webui using git clone, then ./webui.sh/bat, there is used global python executable and global environment until activate command

@MarcusNyne
Copy link
Contributor Author

Maybe I misunderstood you. What do you mean python's executable is located locally? It only exists on windows and only in the portable binary release. If you install webui using git clone, then ./webui.sh/bat, there is used global python executable and global environment until activate command

@light-and-ray, the virtual environment is created and available for use after the python -m venv command. Activate.bat is simply a shorthand that allows you to run multiple commands in the context of the virtual environment. To run a single command in the virtual environment, you can call python.exe in the Scripts folder directly. In linux, it is the "bin" folder, but same concept.

This is described on https://realpython.com/python-virtual-environments-a-primer/
Screenshot below. You can test this by running these commands:

@Rem TESTPIP.BAT
@echo GLOBAL: USING PYTHON
python -m pip list >testpip_global.txt

@echo LOCAL: USING VENV\SCRIPTS\PYTHON
venv\Scripts\python.exe -m pip list >testpip_scripts_python.txt

@echo LOCAL: USING ACTIVATE
call venv\Scripts\activate.bat
python -m pip list > testpip_scripts_activate.txt

activate_clip

@light-and-ray
Copy link
Contributor

Understand

@AUTOMATIC1111 AUTOMATIC1111 merged commit 5abdf51 into AUTOMATIC1111:dev Jun 8, 2024
3 checks passed
@lawchingman lawchingman mentioned this pull request Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants