stable diffusion生成图片权限报错,PermissionError: [Errno 13] Permissi ...

打印 上一主题 下一主题

主题 474|帖子 474|积分 1422

因为我这边用的是远程服务器,我没有管理员权限,所以网上其他人说的sudo什么的方法对我都没有用,我又去找了其他的方法,在https://blog.csdn.net/wandererXX/article/details/136935596
这篇博客里面说到了‘
  1. TMPDIR="user/tmp" python app.py
复制代码
‘这种方法,但是我的运行下令是bash webui.sh,就只能够去改webui.sh里面的源代码了。
只需要在脚本的开头部门设置TMPDIR环境变量为你想要的临时文件路径,然后修改相应的地方来确保步伐使用了这个指定的路径。更改如下:
  1. #!/usr/bin/env bash
  2. #################################################
  3. # Please do not make any changes to this file,  #
  4. # change the variables in webui-user.sh instead #
  5. #################################################
  6. # Set the temporary directory path where the program will create temporary files
  7. TMPDIR="user/tmp"
  8. SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  9. # If run from macOS, load defaults from webui-macos-env.sh
  10. if [[ "$OSTYPE" == "darwin"* ]]; then
  11.     if [[ -f "$SCRIPT_DIR"/webui-macos-env.sh ]]
  12.         then
  13.         source "$SCRIPT_DIR"/webui-macos-env.sh
  14.     fi
  15. fi
  16. # Read variables from webui-user.sh
  17. # shellcheck source=/dev/null
  18. if [[ -f "$SCRIPT_DIR"/webui-user.sh ]]
  19. then
  20.     source "$SCRIPT_DIR"/webui-user.sh
  21. fi
  22. # If $venv_dir is "-", then disable venv support
  23. use_venv=1
  24. if [[ $venv_dir == "-" ]]; then
  25.   use_venv=0
  26. fi
  27. # Set defaults
  28. # Install directory without trailing slash
  29. if [[ -z "${install_dir}" ]]
  30. then
  31.     install_dir="$SCRIPT_DIR"
  32. fi
  33. # Name of the subdirectory (defaults to stable-diffusion-webui)
  34. if [[ -z "${clone_dir}" ]]
  35. then
  36.     clone_dir="stable-diffusion-webui"
  37. fi
  38. # python3 executable
  39. if [[ -z "${python_cmd}" ]]
  40. then
  41.     python_cmd="python3"
  42. fi
  43. # git executable
  44. if [[ -z "${GIT}" ]]
  45. then
  46.     export GIT="git"
  47. else
  48.     export GIT_PYTHON_GIT_EXECUTABLE="${GIT}"
  49. fi
  50. # python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
  51. if [[ -z "${venv_dir}" ]] && [[ $use_venv -eq 1 ]]
  52. then
  53.     venv_dir="venv"
  54. fi
  55. if [[ -z "${LAUNCH_SCRIPT}" ]]
  56. then
  57.     LAUNCH_SCRIPT="launch.py"
  58. fi
  59. # Set the TMPDIR environment variable to the specified temporary directory path
  60. export TMPDIR
  61. # this script cannot be run as root by default
  62. can_run_as_root=0
  63. # read any command line flags to the webui.sh script
  64. while getopts "f" flag > /dev/null 2>&1
  65. do
  66.     case ${flag} in
  67.         f) can_run_as_root=1;;
  68.         *) break;;
  69.     esac
  70. done
  71. # Disable sentry logging
  72. export ERROR_REPORTING=FALSE
  73. # Do not reinstall existing pip packages on Debian/Ubuntu
  74. export PIP_IGNORE_INSTALLED=0
  75. # Pretty print
  76. delimiter="################################################################"
  77. printf "\n%s\n" "${delimiter}"
  78. printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n"
  79. printf "\e[1m\e[34mTested on Debian 11 (Bullseye), Fedora 34+ and openSUSE Leap 15.4 or newer.\e[0m"
  80. printf "\n%s\n" "${delimiter}"
  81. # Do not run as root
  82. if [[ $(id -u) -eq 0 && can_run_as_root -eq 0 ]]
  83. then
  84.     printf "\n%s\n" "${delimiter}"
  85.     printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m"
  86.     printf "\n%s\n" "${delimiter}"
  87.     exit 1
  88. else
  89.     printf "\n%s\n" "${delimiter}"
  90.     printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
  91.     printf "\n%s\n" "${delimiter}"
  92. fi
  93. if [[ $(getconf LONG_BIT) = 32 ]]
  94. then
  95.     printf "\n%s\n" "${delimiter}"
  96.     printf "\e[1m\e[31mERROR: Unsupported Running on a 32bit OS\e[0m"
  97.     printf "\n%s\n" "${delimiter}"
  98.     exit 1
  99. fi
  100. if [[ -d .git ]]
  101. then
  102.     printf "\n%s\n" "${delimiter}"
  103.     printf "Repo already cloned, using it as install directory"
  104.     printf "\n%s\n" "${delimiter}"
  105.     install_dir="${PWD}/../"
  106.     clone_dir="${PWD##*/}"
  107. fi
  108. # Check prerequisites
  109. gpu_info=$(lspci 2>/dev/null | grep -E "VGA|Display")
  110. case "$gpu_info" in
  111.     *"Navi 1"*)
  112.         export HSA_OVERRIDE_GFX_VERSION=10.3.0
  113.         if [[ -z "${TORCH_COMMAND}" ]]
  114.         then
  115.             pyv="$(${python_cmd} -c 'import sys; print(".".join(map(str, sys.version_info[0:2])))')"
  116.             if [[ $(bc <<< "$pyv <= 3.10") -eq 1 ]]
  117.             then
  118.                 # Navi users will still use torch 1.13 because 2.0 does not seem to work.
  119.                 export TORCH_COMMAND="pip install torch==1.13.1+rocm5.2 torchvision==0.14.1+rocm5.2 --index-url https://download.pytorch.org/whl/rocm5.2"
  120.             else
  121.                 printf "\e[1m\e[31mERROR: RX 5000 series GPUs must be using at max python 3.10, aborting...\e[0m"
  122.                 exit 1
  123.             fi
  124.         fi
  125.     ;;
  126.     *"Navi 2"*) export HSA_OVERRIDE_GFX_VERSION=10.3.0
  127.     ;;
  128.     *"Navi 3"*) [[ -z "${TORCH_COMMAND}" ]] && \
  129.          export TORCH_COMMAND="pip install torch torchvision --index-url https://download.pytorch.org/whl/test/rocm5.6"
  130.         # Navi 3 needs at least 5.5 which is only on the torch 2.1.0 release candidates right now
  131.     ;;
  132.     *"Renoir"*) export HSA_OVERRIDE_GFX_VERSION=9.0.0
  133.         printf "\n%s\n" "${delimiter}"
  134.         printf "Experimental support for Renoir: make sure to have at least 4GB of VRAM and 10GB of RAM or enable cpu mode: --use-cpu all --no-half"
  135.         printf "\n%s\n" "${delimiter}"
  136.     ;;
  137.     *)
  138.     ;;
  139. esac
  140. if ! echo "$gpu_info" | grep -q "NVIDIA";
  141. then
  142.     if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]]
  143.     then
  144.         export TORCH_COMMAND="pip install torch==2.0.1+rocm5.4.2 torchvision==0.15.2+rocm5.4.2 --index-url https://download.pytorch.org/whl/rocm5.4.2"
  145.     fi
  146. fi
  147. for preq in "${GIT}" "${python_cmd}"
  148. do
  149.     if ! hash "${preq}" &>/dev/null
  150.     then
  151.         printf "\n%s\n" "${delimiter}"
  152.         printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
  153.         printf "\n%s\n" "${delimiter}"
  154.         exit 1
  155.     fi
  156. done
  157. if [[ $use_venv -eq 1 ]] && ! "${python_cmd}" -c "import venv" &>/dev/null
  158. then
  159.     printf "\n%s\n" "${delimiter}"
  160.     printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m"
  161.     printf "\n%s\n" "${delimiter}"
  162.     exit 1
  163. fi
  164. cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"; exit 1; }
  165. if [[ -d "${clone_dir}" ]]
  166. then
  167.     cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
  168. else
  169.     printf "\n%s\n" "${delimiter}"
  170.     printf "Clone stable-diffusion-webui"
  171.     printf "\n%s\n" "${delimiter}"
  172.     "${GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}"
  173.     cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
  174. fi
  175. if [[ $use_venv -eq 1 ]] && [[ -z "${VIRTUAL_ENV}" ]];
  176. then
  177.     printf "\n%s\n" "${delimiter}"
  178.     printf "Create and activate python venv"
  179.     printf "\n%s\n" "${delimiter}"
  180.     cd "${install_dir}"/"${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
  181.     if [[ ! -d "${venv_dir}" ]]
  182.     then
  183.         "${python_cmd}" -m venv "${venv_dir}"
  184.         first_launch=1
  185.     fi
  186.     # shellcheck source=/dev/null
  187.     if [[ -f "${venv_dir}"/bin/activate ]]
  188.     then
  189.         source "${venv_dir}"/bin/activate
  190.     else
  191.         printf "\n%s\n" "${delimiter}"
  192.         printf "\e[1m\e[31mERROR: Cannot activate python venv, aborting...\e[0m"
  193.         printf "\n%s\n" "${delimiter}"
  194.         exit 1
  195.     fi
  196. else
  197.     printf "\n%s\n" "${delimiter}"
  198.     printf "python venv already activate or run without venv: ${VIRTUAL_ENV}"
  199.     printf "\n%s\n" "${delimiter}"
  200. fi
  201. # Try using TCMalloc on Linux
  202. prepare_tcmalloc() {
  203.     if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then
  204.         TCMALLOC="$(PATH=/sbin:$PATH ldconfig -p | grep -Po "libtcmalloc(_minimal|)\.so\.\d" | head -n 1)"
  205.         if [[ ! -z "${TCMALLOC}" ]]; then
  206.             echo "Using TCMalloc: ${TCMALLOC}"
  207.             export LD_PRELOAD="${TCMALLOC}"
  208.         else
  209.             printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
  210.         fi
  211.     fi
  212. }
  213. KEEP_GOING=1
  214. export SD_WEBUI_RESTART=tmp/restart
  215. while [[ "$KEEP_GOING" -eq "1" ]]; do
  216.     if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]; then
  217.         printf "\n%s\n" "${delimiter}"
  218.         printf "Accelerating launch.py..."
  219.         printf "\n%s\n" "${delimiter}"
  220.         prepare_tcmalloc
  221.         accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
  222.     else
  223.         printf "\n%s\n" "${delimiter}"
  224.         printf "Launching launch.py..."
  225.         printf "\n%s\n" "${delimiter}"
  226.         prepare_tcmalloc
  227.         "${python_cmd}" -u "${LAUNCH_SCRIPT}" "$@"
  228.     fi
  229.     if [[ ! -f tmp/restart ]]; then
  230.         KEEP_GOING=0
  231.     fi
  232. done
复制代码
###我们只需要将前面的TMPDIR="user/tmp",中的‘user/tmp’改成我们有权限访问的文件夹目录即可

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

曹旭辉

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表