Sxela / WarpFusion

WarpFusion
Other
958 stars 105 forks source link

File missing! #86

Open aarvndhNG opened 10 months ago

aarvndhNG commented 10 months ago

[Errno 2] No such file or directory: 'runas' Iam using Local installation guide for Linux-Ubuntu 22.04 (venv): on kaggle

Sxela commented 10 months ago

You mean this installer? https://github.com/Sxela/WarpFusion/blob/main/linux_install.sh

aarvndhNG commented 10 months ago

Yes I just transferred the sh code in to a python code by chatgpt so it works properly

aarvndhNG commented 10 months ago
import subprocess
import sys

# Get the directory where this Python script is located
script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))

# Define the paths to various directories and files
python_dir = os.path.join(script_dir, "python")
scripts_dir = os.path.join(python_dir, "Scripts")
lib_dir = os.path.join(python_dir, "Lib", "site-packages")
pip_py = os.path.join(script_dir, "get-pip.py")
venv_dir = os.path.join(script_dir, "env")

# Check if Git is already installed
git_installed = subprocess.run(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0

if git_installed:
    print("Skipping git as it's installed.")
else:
    print("Git not installed, please run install.bat")
    print("Exiting.")
    exit(-1)

# Check if the virtual environment is installed
venv_activate = os.path.join(venv_dir, "Scripts", "activate")
venv_installed = os.path.exists(venv_activate)

if not venv_installed:
    print("Virtual env not installed, please run install.bat")
    print("Exiting.")
    exit(-1)

# Set variables to skip installation inside the notebook
os.environ["IS_DOCKER"] = "1"
os.environ["IS_LOCAL_INSTALL"] = "1"

# Activate the virtual environment
print("Activating virtual environment")
subprocess.run([venv_activate], shell=True)

# Check for the availability of CUDA
cuda_available = subprocess.run(["python", "-c", "import torch; from xformers import ops; assert torch.cuda.is_available()"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0

if not cuda_available:
    print("Cuda not available, please run install.bat")
    exit(-1)

# Launch the Jupyter server
print("Launching Jupyter server.")
print("-----")
print("After the server has launched, go to https://colab.research.google.com")
print("Click File -> Upload Notebook and upload the *.ipynb file")
print("Click on the dropdown menu near 'Connect' or 'Reconnect' button on the top-right part of the interface.")
print("Select 'connect to a local runtime' and paste the URL that will be generated below,")
print("which looks like 'http://localhost:8888/?token=somenumbers'")
print("Click 'Connect' and CTRL+F9 to run all cells.")
print("------")
subprocess.run(["jupyter", "notebook", "./", "--NotebookApp.allow_origin='https://colab.research.google.com'", "--no-browser", "--port=8888", "--NotebookApp.port_retries=0"])
print("Press <ENTER> to continue..")
subprocess.run(["/user:Administrator", "/u", "\"\""], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("Deactivating virtual environment...")

# Deactivate the virtual environment
subprocess.run([venv_activate, "deactivate"])
aarvndhNG commented 10 months ago

What is the issue? Is it actually a file missing?

Sxela commented 10 months ago

I suppose runas is a command to run as some user.

aarvndhNG commented 10 months ago

So how do I install that?

Sxela commented 10 months ago

0_0 you want to install runas? @mike-rowley can you help here?

aarvndhNG commented 10 months ago

0_0 you want to install runas? @mike-rowley can you help here?

Okay

mike-rowley commented 10 months ago

runas appears to be su for non-root users as per https://manpages.ubuntu.com/manpages/lunar/en/man8/runas.8.html

Not sure where runas comes in, has to be something to do with the sh to python conversion The sh script worked fine for me on a new venv, not sure why python is needed to "run properly"

And the attached set of code is certainly not correctly converted as there seems to be no installs of the required packages. I would say that it is a chatgpt issue.

aarvndhNG commented 10 months ago

Okay thanks

aarvndhNG commented 10 months ago

Hey @mike-rowley I tried several times and i finally get it from the chatGPT i hope it works and it takes some much time to env iam waiting for the final installation process The code I used

import subprocess
import sys

# Prompt for Warp version
warp_version = input("Your Warpfusion Version:")

# Create the directory structure with the specified version
warp_directory = os.path.join(os.getcwd(), f"WarpFusion {warp_version}")
os.makedirs(warp_directory, exist_ok=True)

# Change to the Warp directory
os.chdir(warp_directory)

# Update and install required packages based on the Linux distribution
def install_packages():
    if os.path.exists("/etc/arch-release"):
        subprocess.run(["sudo", "pacman", "-Syu"])
        subprocess.run(["sudo", "pacman", "-S", "--needed", "git", "python", "python-pip", "python-opencv", "imagemagick", "ffmpeg", "jupyter-notebook", "python-virtualenv"])
    elif os.path.exists("/etc/debian-version"):
        subprocess.run(["sudo", "apt", "update"])
        subprocess.run(["sudo", "apt", "install", "-y", "git", "python3.10", "python3-pip", "python3-opencv", "imagemagick", "ffmpeg", "jupyter-notebook", "python3.10-venv"])
    else:
        print("This program is officially supported only on Arch and Debian based distributions.")
        response = input("Would you like to proceed with installing required dependencies? (Y/N): ").lower()
        if response != "y":
            print("Exiting installer.")
            sys.exit()

install_packages()

# Get the current directory
current_dir = os.getcwd()
print(f"Current directory: {current_dir}")

# Function to create and activate a Python virtual environment
def create_and_activate_virtualenv():
    if not os.path.exists("warpenv"):
        print("Creating Python virtual environment...")
        subprocess.run(["python3", "-m", "venv", "warpenv"])
    print("Activating virtual environment...")
    activate_script = os.path.join("warpenv", "bin", "activate")
    subprocess.run(["source", activate_script], shell=True)

create_and_activate_virtualenv()

# Check if required Python packages are already installed
required_packages = ["torch", "torchvision", "torchaudio", "xformers", "onnxruntime", "onnxruntime-gpu", "gdown", "diffusers", "requests", "mediapipe", "piexif", "safetensors", "lark", "Pillow", "wget", "webdataset", "open_clip_torch", "opencv-python", "pandas", "matplotlib", "fvcore", "ipywidgets", "transformers", "omegaconf", "einops", "pytorch_lightning", "scikit-image", "opencv-python", "ai-tools", "cognitive-face", "zprint", "kornia", "lpips", "keras", "datetime", "timm", "prettytable", "basicsr", "fairscale", "realesrgan", "torchmetrics"]
installed_packages = subprocess.check_output(["pip", "list"]).decode()
for package in required_packages:
    if package not in installed_packages:
        subprocess.run(["pip", "install", package])

# Function to clone or refresh a Git repository
def clone_or_refresh_repo(repo_url, install_cmd=None, repo_dir=None):
    repo_name = os.path.basename(repo_url.split(".git")[0])
    if repo_dir is None:
        repo_dir = repo_name
    if not os.path.exists(repo_name):
        print(f"Cloning {repo_name}...")
        subprocess.run(["git", "clone", repo_url, os.path.join("content", repo_dir)])
    else:
        print(f"Updating {repo_name}...")
        os.chdir(repo_name)
        subprocess.run(["git", "pull"])
        os.chdir("..")
    if install_cmd:
        subprocess.run(install_cmd, shell=True)

# Switch back to the Warp directory
os.chdir(warp_directory)

# Clone and install repositories with conditions
clone_or_refresh_repo("https://github.com/Sxela/sxela-stablediffusion.git", "pip install -e content/stablediffusion", "stablediffusion")
clone_or_refresh_repo("https://github.com/Sxela/Segment-and-Track-Anything-CLI.git", "pip install -e content/Segment-and-Track-Anything-CLI/sam")
clone_or_refresh_repo("https://github.com/Sxela/ControlNet-v1-1-nightly.git", None, "ControlNet")
clone_or_refresh_repo("https://github.com/CompVis/taming-transformers.git", "pip install -e content/taming-transformers")
clone_or_refresh_repo("https://github.com/openai/CLIP.git", "pip install -e content/CLIP")
clone_or_refresh_repo("https://github.com/IDEA-Research/GroundingDINO.git")
clone_or_refresh_repo("https://github.com/crowsonkb/guided-diffusion.git", "pip install -e content/guided-diffusion")
clone_or_refresh_repo("https://github.com/Sxela/k-diffusion.git", "pip install -e content/k-diffusion")
clone_or_refresh_repo("https://github.com/assafshocher/ResizeRight.git")
clone_or_refresh_repo("https://github.com/salesforce/BLIP.git")
clone_or_refresh_repo("https://github.com/pengbo-learn/python-color-transfer.git")
clone_or_refresh_repo("https://github.com/Stability-AI/generative-models.git")
clone_or_refresh_repo("https://github.com/Sxela/ComfyUI")
clone_or_refresh_repo("https://github.com/guoyww/AnimateDiff.git")

# Additional repositories
#os.chdir("content")
#os.chdir("comfyui-animatediff")
#subprocess.run(["git", "checkout", "9d32153349aa15c6867a61f65b3e4bec74aa403a"])
#os.chdir(warp_directory)

# Set JUPYTER_CONFIG_DIR to specify the configuration directory
os.environ["JUPYTER_CONFIG_DIR"] = os.path.join(os.getcwd(), ".jupyter")

# Install Jupyter kernel and extensions
os.chdir("warpenv")
activate_script = os.path.join("bin", "activate")
subprocess.run(["source", activate_script], shell=True)
print("Installing Jupyter kernel and extensions...")
subprocess.run(["pip", "install", "entrypoints==0.4", "ipython==8.10.0", "jupyter_client==7.4.9", "jupyter_core==5.2.0", "packaging==22.0", "tzdata==2022.7", "traitlets==5.9.0", "ipykernel", "--force-reinstall", "diffusers==0.11.1", "nbclassic", "gdown"])
subprocess.run(["python", "-m", "ipykernel", "install", "--user"])
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "jupyter_http_over_ws>=0.0.7"])
subprocess.run(["jupyter", "serverextension", "enable", "--py", "jupyter_http_over_ws"])

# Create symbolic link for libnvrtc
print("Creating symbolic link for libnvrtc...")
nvrtc_link = os.path.join(os.path.expanduser("~"), ".local", "lib", "python3.10", "site-packages", "torch", "lib", "libnvrtc-672ee683.so.11.2")
os.symlink(nvrtc_link, os.path.join(warp_directory, "warpenv", "lib", "python3.10", "site-packages", "torch", "lib", "libnvrtc.so"))

# Create run_linux.sh
with open("run_linux.sh", "w") as run_script:
    run_script.write('''#!/bin/bash

# Define directories and files
VENV_DIR=$(pwd)/warpenv

# Check if Git is installed
if git --version >/dev/null 2>&1; then
    echo "Skipping git as it's installed."
else
    echo "Git not installed. Please install Git first."
    echo "Exiting."
    exit 1
fi

# Check if Virtual Environment is installed
if [ ! -f "${VENV_DIR}/bin/activate" ]; then
    echo "Virtual env not installed. Please run install.sh"
    echo "Exiting."
    exit 1
fi

# Setting variables to skip install inside the notebook
export IS_DOCKER=1
export IS_LOCAL_INSTALL=1

# Activate virtual environment
echo "Activating virtual environment."
source ${VENV_DIR}/bin/activate

# Check for required Python packages
python -c "import torch; from xformers import ops; assert torch.cuda.is_available(), 'Cuda not available, please check your apt repositories'"
if [ $? -eq 1 ]; then
    exit 1
fi

# Change into 'content' directory
cd content || { echo "Directory content not found. Exiting."; exit 1; }

# Set JUPYTER_CONFIG_DIR to specify the configuration directory
export JUPYTER_CONFIG_DIR=$(pwd)/.jupyter

# Launch Jupyter server
echo "Launching Jupyter server."
echo "-----"
echo "After the server has launched, go to https://colab.research.google.com"
echo "Click File -> Upload Notebook and upload the *.ipynb file"
echo "Click on the dropdown menu near 'Connect' or 'Reconnect' button on the top-right part of the interface."
echo "Select 'connect to a local runtime' and paste the URL that will be generated below,"
echo "which looks like 'http://localhost:8888/?token=somenumbers'"
echo "Click 'Connect' and CTRL+F9 to run all cells."
echo "------"
jupyter notebook  --allow-root --ServerApp.open_browser=False --no-browser --ServerApp.allow_remote_access=True --ServerApp.allow_origin='https://colab.research.google.com' --port=8888 --ServerApp.port_retries=0 --ip=0.0.0.0

# Deactivate virtual environment
echo "Deactivating virtual environment..."
deactivate
# Return to WarpFusion Directory from content directory
cd ..''')