stable-diffusion-webui
stable-diffusion-webui copied to clipboard
When creating a virtual environment, upgrade pip in webui.bat/webui.sh
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:
- Before fix: clip==1.0 cstr==0.1.0
- After fix: clip @ https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip#sha256=b5842c25da441d6c581b53a5c60e0c2127ebafe0f746f8e15561a006c6c3be6a cstr @ git+https://github.com/WASasquatch/cstr@0520c29a18a7a869a6e5983861d6f7a4c86f8e9b
Checklist:
- [x] I have read contributing wiki page
- [x] I have performed a self-review of my own code
- [x] My code follows the style guidelines
- [x] My code passes tests
Note: tested on Windows and Darwin Linux (Mac)
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
You are making an extension - you can add this upgrade in it's install.py file or left in installation instruction
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.
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
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
Understand