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

File missing! #86

Open
aarvndhNG opened this issue Nov 1, 2023 · 11 comments
Open

File missing! #86

aarvndhNG opened this issue Nov 1, 2023 · 11 comments

Comments

@aarvndhNG
Copy link

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

@Sxela
Copy link
Owner

Sxela commented Nov 1, 2023

@aarvndhNG
Copy link
Author

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

@aarvndhNG
Copy link
Author

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
Copy link
Author

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

@Sxela
Copy link
Owner

Sxela commented Nov 1, 2023

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

@aarvndhNG
Copy link
Author

So how do I install that?

@Sxela
Copy link
Owner

Sxela commented Nov 2, 2023

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

@aarvndhNG
Copy link
Author

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

Okay

@mike-rowley
Copy link
Contributor

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
Copy link
Author

Okay thanks

@aarvndhNG
Copy link
Author

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 ..''')

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

No branches or pull requests

3 participants